2016-12-20 10 views
1

検索ビューにプロセスバーを追加します。しかし、searchPlateはnullを返します。Xamarin.Android検索ビューにプロセスバーを追加する方法

public void showProgressBar(SearchView searchView, Activity context) 
{ 
    var id = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null); 
    var searchPlate = searchView.FindViewById(id); 

    ... 
} 

私はメニューに

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <item android:id="@+id/action_item_search" 
     android:title="Seach Item" 
     android:icon="@drawable/ic_search_black_24dp" 
     app:showAsAction="always|collapseActionView" 
     app:actionViewClass="android.support.v7.widget.SearchView" /> 
</menu> 

答えて

0

アンドロイド検索ビューを作成


更新

私を助けてください:ID/search_plateはSearchViewでいくつかの背景アートワークを指します。これをプログレスバーに置き換えることはできません。 SearchViewはLinearLayoutを拡張しているので、SearchViewを使用してLinearLayoutで実行できることは何でもできます。ただし、SearchViewは特別な目的のビューです。私はデフォルトの動作を変更することをお勧めしません。ですから、ProgressBarをSearchViewの右側に追加してProgressBarを不確定モードにすることをお勧めします。これは回転ホイールです。

+0

私はxamarinにhttp://stackoverflow.com/a/26143787/1268455を実装しようとしたがsearchPlate = nullをしています。 –

0

私はあなたのコードで私の側にsearchPlateを取得することができます:

public class MainActivity : Activity 
{ 
     SearchView sv; 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 
      // Set our view from the "main" layout resource 
      SetContentView (Resource.Layout.Main); 
      sv = FindViewById<SearchView>(Resource.Id.searchView1); 
      showProgressBar(sv, this); 
     } 

     void showProgressBar(SearchView searchView, Context context) 
     { 
      int id = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null); 
      View searchPlate = searchView.FindViewById(id); 

      if (searchView.FindViewById(id).FindViewById(Resource.Id.progressBar1) != null) 
      { 
       searchView.FindViewById(id).FindViewById(Resource.Id.progressBar1).Animate().SetDuration(200).Alpha(1).Start(); 
      } 
      else 
      { 
       View v = LayoutInflater.From(context).Inflate(Resource.Layout.loading, null); 
       ((ViewGroup)searchView.FindViewById(id)).AddView(v, 1); 
      } 
     } 
    } 

あなたは私のプロジェクトを参照すると、コアの問題を見つけることができます。

Here is the project address

enter image description here

+0

デモをありがとうございます。しかし、メニューを使用して検索ビューを作成します。 –

+0

@TuanHoangAnhあなたは 'search_plate'がnullであると言っています。その前にメニューからsearchViewオブジェクトをどうやって取得しましたか? –

関連する問題