把进度微调的搜索查看? [英] Put a progress spinner in a SearchView?

查看:174
本文介绍了把进度微调的搜索查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是搜索查看我的活动。在用户键入,我执行搜索请求到服务器。我想表明,一些活动正在发生的事情。是否可以显示搜索查看内的进步微调?

I'm using a SearchView in my Activity. As the user types, I am performing search requests to a server. I want to indicate that some activity is happening. Is it possible to display a progress spinner within the SearchView?

否则,人们如何处理这 - ?我们创建一个自定义动作条父母的布局,并嵌入内搜索查看

Otherwise, how are people handling this - do we create a custom actionbar parent layout, and within that embed the SearchView?

<LinearLayout orientation="horizontal">
    <SearchView />
    <ProgressBar />
</LinearLayout>

感谢您

推荐答案

首先创建进度条的布局。像这样的XML应该做的工作:

First create the layout for the progressbar. A XML like this should do the job:

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>

接下来,创建两个函数。一个显示进度条上的搜索查看等来隐藏它:

Next create two functions. One to show the progress bar on your searchview and other to hide it:

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();
}

这篇关于把进度微调的搜索查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆