Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 如何在xamarin表单中隐藏搜索栏中的搜索图标_Xaml_Search_Xamarin.forms_Searchbar - Fatal编程技术网

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

Xaml 如何在xamarin表单中隐藏搜索栏中的搜索图标,xaml,search,xamarin.forms,searchbar,Xaml,Search,Xamarin.forms,Searchbar,我想在Xamarin表单中隐藏搜索栏中的搜索图标。这就是我需要的UI 这是我正在使用的自定义渲染器 [assembly: ExportRenderer(typeof(searchTab), typeof(StyledSearchBarRenderer))] namespace RestaurantApp.Droid.Renderers { class StyledSearchBarRenderer : SearchBarRenderer { protected

我想在Xamarin表单中隐藏搜索栏中的搜索图标。这就是我需要的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);

            }
        }
    }
}
[程序集:ExportRenderer(typeof(searchTab)、typeof(styledSearchBallenderer))]
命名空间RestaurantApp.Droid.Renderers
{
类StyledSearchBallenderer:SearchBallenderer
{
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(控件!=null)
{
var color=global::Xamarin.Forms.color.LightGray;
var searchView=作为searchView的控件;
int searchPlateId=searchView.Context.Resources.GetIdentifier(“android:id/search\u plate”,null,null);
Android.Views.View searchPlateView=searchView.findviewbyd(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表单中,我没有得到任何示例或代码来实现这一点。有什么建议吗?

在我的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);
var searchView=base.Control作为searchView;
int searchIconId=Context.Resources.GetIdentifier(“android:id/search\u mag\u icon”,null,null);
ImageView searchViewIcon=(ImageView)searchView.FindViewById(searchIconId);
searchViewIcon.setImageDrawable(空);
这将清除搜索图标

如有疑问,请随时回复