将进度微调器放在SearchView中?

use*_*425 4 android

我在我的Activity中使用了SearchView.当用户输入时,我正在向服务器执行搜索请求.我想表明一些活动正在发生.是否可以在SearchView中显示进度微调器?

否则,人们如何处理这个问题 - 我们是否创建了自定义操作栏父布局,并在其中嵌入了SearchView?

<LinearLayout orientation="horizontal">
    <SearchView />
    <ProgressBar />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

谢谢

Ped*_*ira 7

首先为进度条创建布局.像这样的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>
Run Code Online (Sandbox Code Playgroud)

接下来创建两个函数.一个用于显示搜索视图上的进度条,另一个用于隐藏它:

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();
}
Run Code Online (Sandbox Code Playgroud)