Xamarin.forms 如何在xamarin表单中移动右侧搜索栏的搜索图标

Xamarin.forms 如何在xamarin表单中移动右侧搜索栏的搜索图标,xamarin.forms,Xamarin.forms,如何在xamarin表单中移动右侧搜索栏的搜索图标。 我正在寻找android和IOS。 对于Android,我使用了searchderer,下面的代码不起作用 有人知道怎么做吗?请帮忙 protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e) { base.OnElementChanged(e); Control.LayoutParamete

如何在xamarin表单中移动右侧搜索栏的搜索图标。 我正在寻找android和IOS。 对于Android,我使用了searchderer,下面的代码不起作用 有人知道怎么做吗?请帮忙

 protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
    {
        base.OnElementChanged(e);
        Control.LayoutParameters=(new ActionBar.LayoutParams(GravityFlags.Right));
    }
protected override void OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
Control.LayoutParameters=(新的ActionBar.LayoutParams(GravityFlags.Right));
}

在android中,通过自定义渲染器,您可以使用以下代码将搜索图标放置在搜索栏的右侧:

    protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
    {
        base.OnElementChanged(e);
        if (e.NewElement != null)
        {
            var searchView = base.Control as SearchView;

            //Get the Id for your search icon
            int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
            ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
            ViewGroup linearLayoutSearchView = (ViewGroup)searchViewIcon.Parent;

            searchViewIcon.SetAdjustViewBounds(true);

            //Remove the search icon from the view group and add it once again to place it at the end of the view group elements
            linearLayoutSearchView.RemoveView(searchViewIcon);
            linearLayoutSearchView.AddView(searchViewIcon);
        }
    }
protected override void OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(例如NewElement!=null)
{
var searchView=base.Control作为searchView;
//获取搜索图标的Id
int searchIconId=Context.Resources.GetIdentifier(“android:id/search\u mag\u icon”,null,null);
ImageView searchViewIcon=(ImageView)searchView.FindViewById(searchIconId);
ViewGroup linearLayoutSearchView=(ViewGroup)searchViewIcon.Parent;
searchViewIcon.SetAdjustViewBounds(true);
//从视图组中删除搜索图标,然后再次添加该图标,以将其放置在视图组元素的末尾
linearLayoutSearchView.RemoveView(搜索视图图标);
linearLayoutSearchView.AddView(搜索视图图标);
}
}
在上面的实现中,我只是从搜索栏视图组中删除了搜索图标,然后再次将其添加到同一视图组中。这会将正常情况下的第一个子项放置到最后一个子项,从而将搜索图标放置在末尾