Сначала создайте макет для панели прогресса. 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>
Далее создайте две функции. Один, чтобы показать индикатор на вашем SearchView и других, чтобы скрыть его:
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();
}
Хорошо, я думаю, что это решение зависит от того, что Google не выпускает обновление, где «search_plate» изменен? – user3203425
Да, да. Вы также можете создать свой собственный SearchView, выполнив его с помощью google sdk. –
Хорошая работа. Благодаря :) –