首先为进度条创建布局。像这样的XML应该做的工作:
R.layout.loading_icon
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/search_progress_bar"
android:layout_marginTop="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
下创建两个功能。一个显示在您的搜索查看进度条等来隐藏它:
public void showProgressBar(SearchView searchView, Context context)
{
int id = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
if (searchView.findViewById(id).findViewById(R.id.search_progress_bar) != null)
searchView.findViewById(id).findViewById(R.id.search_progress_bar).animate().setDuration(200).alpha(1).start();
else
{
View v = LayoutInflater.from(context).inflate(R.layout.loading_icon, null);
((ViewGroup) searchView.findViewById(id)).addView(v, 1);
}
}
public void hideProgressBar(SearchView searchView)
{
int id = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
if (searchView.findViewById(id).findViewById(R.id.search_progress_bar) != null)
searchView.findViewById(id).findViewById(R.id.search_progress_bar).animate().setDuration(200).alpha(0).start();
}
好吧,我正确地认为这个解决方案依赖于谷歌没有发布更新“search_plate”更改的事实吗? – user3203425 2014-10-02 19:19:31
是的。您也可以通过应对Google sdk中的一个来创建自己的SearchView。 – 2014-10-02 19:21:07
不错的工作。谢谢 :) – 2015-06-12 11:49:44