먼저 진행 표시 줄 레이아웃을 만듭니다. 이 같은 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
예. Google sdk에서 대처하여 자신의 SearchView를 만들 수도 있습니다. –
잘 했어. 감사 :) –