如何在 xamarin 表单中隐藏搜索栏中的搜索图标

How to hide the search icon in the search bar in xamarin forms

我想在 Xamarin Forms 的搜索栏中隐藏搜索图标。这是我需要的UI。

这是我正在使用的自定义渲染器

[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);

            }
        }
    }
}

这是我的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>

这就是我要隐藏的东西

我没有得到任何示例或任何代码来在 Xamarin Forms 中完成此操作。有什么建议吗?

我的 Android 渲染器是这样的:

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);

这应该清除搜索图标

如有疑问,请随时回复。