2017-12-09 12 views
2

xamarinフォームの右側にある検索バーの検索アイコンを移動する方法。 私はアンドロイドとIOSを探しています。 Androidの場合は、SearchBarRendererを使用しました。以下のコードでは機能しません。 誰でも知っている人はいらっしゃいますか。アンドロイドでxamarinフォームの右側にある検索バーの検索アイコンを移動する方法

protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e) 
    { 
     base.OnElementChanged(e); 
     Control.LayoutParameters=(new ActionBar.LayoutParams(GravityFlags.Right)); 
    } 

答えて

0

は、カスタムレンダラで、あなたは検索バーの右側にある検索アイコンを配置するには、次のコードを使用することができます。

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

上記の実装では、私は単に削除します検索バービューグループの検索アイコンをクリックし、同じビューグループに再度追加します。通常、最初の子を最後の子に置き、検索アイコンを最後に配置します。

関連する問題