[英]How to hide the search icon in the search bar in xamarin forms
I want to hide the search icon in the search bar in Xamarin Forms. 我想在Xamarin Forms中的搜索栏中隐藏搜索图标。 This is the UI I require. 这是我需要的UI。
This is the custom renderer I'm using 这是我正在使用的自定义渲染器
[assembly: ExportRenderer(typeof(searchTab), typeof(StyledSearchBarRenderer))]
namespace RestaurantApp.Droid.Renderers
{
class StyledSearchBarRenderer : SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var color = global::Xamarin.Forms.Color.LightGray;
var searchView = Control as SearchView;
int searchPlateId = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);
Android.Views.View searchPlateView = searchView.FindViewById(searchPlateId);
searchPlateView.SetBackgroundColor(Android.Graphics.Color.Transparent);
}
}
}
}
This is my XAML code 这是我的XAML代码
<Frame Padding="0" OutlineColor="DarkGray" HasShadow="True" HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<local:searchTab x:Name="searchBar" Placeholder="Please search for a vendor or product name" PlaceholderColor="Black" TextColor="Black" HorizontalOptions="FillAndExpand" VerticalOptions="Center" />
</Frame>
This is what I have to hide 这就是我要隐藏的
I'm not getting any examples or any code to accomplish this in Xamarin Forms. 我没有在Xamarin Forms中获得任何示例或任何代码来完成此任务。 any suggestions? 有什么建议么?
How I would do it is something like this in my Android Renderer: 在Android Renderer中,我的操作方式如下:
var searchView = base.Control as SearchView;
int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
searchViewIcon.setImageDrawable(null);
This should clear the search icon 这应该清除搜索图标
In case of queries feel free to revert. 如有查询,请随时还原。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.