Android如何将processbar添加到搜索视图

Android如何将processbar添加到搜索视图,android,xamarin.android,Android,Xamarin.android,我想将processbar添加到搜索视图。但搜索板返回空值 public void showProgressBar(SearchView searchView, Activity context) { var id = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null); var searchPlate = searchView.FindViewById(id);

我想将processbar添加到搜索视图。但搜索板返回空值

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>


android:id/search\u plate指的是SearchView中的一些背景艺术品。您不能将其替换为进度条。SearchView扩展了LinearLayout,因此任何可以使用LinearLayout完成的操作都可以使用SearchView完成。但是,SearchView是一个特殊用途的视图。我不建议修改它的默认行为。因此,我建议将ProgressBar添加到SearchView的右侧,并将ProgressBar置于不确定模式,这是一个旋转的轮子。

android:id/search\u plate指的是SearchView中的一些背景艺术品。您不能将其替换为进度条。SearchView扩展了LinearLayout,因此任何可以使用LinearLayout完成的操作都可以使用SearchView完成。但是,SearchView是一个特殊用途的视图。我不建议修改它的默认行为。因此,我建议将ProgressBar添加到SearchView的右侧,并将ProgressBar置于不确定模式,这是一个旋转的轮子。

我可以使用您的代码在我的一侧获取搜索板:

 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);
            }
        }
  }
公共类main活动:活动
{
SearchView sv;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
sv=findviewbyd(Resource.Id.searchView1);
showProgressBar(sv,this);
}
void showProgressBar(SearchView SearchView,上下文)
{
intid=searchView.Context.Resources.GetIdentifier(“android:id/search\u plate”,null,null);
View searchPlate=searchView.FindViewById(id);
if(searchView.findviewbyd(id).findviewbyd(Resource.id.progressBar1)!=null)
{
searchView.findviewbyd(id).findviewbyd(Resource.id.progressBar1.Animate().SetDuration(200.Alpha(1.Start));
}
其他的
{
视图v=LayoutInflater.From(上下文)。充气(Resource.Layout.loading,null);
((视图组)searchView.FindViewById(id)).AddView(v,1);
}
}
}
你可以参考我的项目,找出核心问题


我可以用你的代码在我身边找到搜索牌:

 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);
            }
        }
  }
公共类main活动:活动
{
SearchView sv;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
sv=findviewbyd(Resource.Id.searchView1);
showProgressBar(sv,this);
}
void showProgressBar(SearchView SearchView,上下文)
{
intid=searchView.Context.Resources.GetIdentifier(“android:id/search\u plate”,null,null);
View searchPlate=searchView.FindViewById(id);
if(searchView.findviewbyd(id).findviewbyd(Resource.id.progressBar1)!=null)
{
searchView.findviewbyd(id).findviewbyd(Resource.id.progressBar1.Animate().SetDuration(200.Alpha(1.Start));
}
其他的
{
视图v=LayoutInflater.From(上下文)。充气(Resource.Layout.loading,null);
((视图组)searchView.FindViewById(id)).AddView(v,1);
}
}
}
你可以参考我的项目,找出核心问题


我尝试在xamarin上实现,但searchPlate=null。我尝试在xamarin上实现,但searchPlate=null。感谢演示。但是我使用菜单创建搜索视图。@TuanHoangAnh你说你得到的
search\u plate
为空,在那之前你是如何从菜单中得到searchView对象的?谢谢演示。但我使用菜单创建搜索视图。@TuanHoangAnh您说您得到的
search\u plate
为空,在此之前您是如何从菜单中得到searchView对象的?