Put a progress spinner in a SearchView?

前端 未结 3 1310
梦如初夏
梦如初夏 2021-01-01 06:03

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

3条回答
  •  粉色の甜心
    2021-01-01 06:21

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

    R.layout.loading_icon

    
    
        
    
    

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

提交回复
热议问题