Home > General > Blur the Background of Android Standard Search Dialog

Blur the Background of Android Standard Search Dialog

How to blur the background of a standard search dialog?

I didn’t find any good solution on this topic in the web. The common response was “it’s not possible”. So I began to figure out a solution by myself, which finally works fine! Let’s start over:

Because you don’t get a handle of the standard android search dialog it seems to be impossible to blur the background by calling

Window.addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

But there is an other approach: Generally you want to perform a search on a list. The ListView can be set on a RelativeLayout. On top of it you can set a View with the android:background=”@drawable/aShape”, which covers the entire ListView. The visibility should be “gone”. The drawable aShape is in my case a gradient with an alpha value.

The RelativeLayout:

<ListView android:id="@+id/list"
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent"               
          android:layout_weight="1"
          android:drawSelectorOnTop="false"/> 
               
<View android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:id="@+id/list_search_overlay" 
      android:layout_height="wrap_content" 
      android:background="@drawable/search_overlay"
      android:visibility="gone"></View>

The shape (search_overlay in my case):

<gradient
    android:startColor="#80000001"
    android:endColor="#80000001"/>

Now onSearchRequested() must be overridden and set the View (in my case R.id.list_search_overlay) to visible. Finally a listener must be registered at SearchManager.setOnDismissListener() to set the View to visible again if the search dialog is closed.

The code (from the activity):

@Override
public boolean onSearchRequested() {
 ((View) findViewById(R.id.list_search_overlay)).setVisibility(View.VISIBLE);
 final SearchManager searchManager = (SearchManager) this.getSystemService
                                                        (this.SEARCH_SERVICE);
 searchManager.setOnDismissListener(new OnDismissListener() {

 @Override
 public void onDismiss() {
  ((View)ServiceListBase.this.
         findViewById(R.id.list_search_overlay)).setVisibility(View.GONE);
 }
});
return super.onSearchRequested();

I hope this will assist you by optimizing the user experience with your app.

Cheers Mavi

Categories: General Tags: , , ,
  1. 30/08/2011 at 15:56 | #1

    You my comrade are a genius

  2. 31/08/2011 at 22:32 | #2

    My ideas exactly!

  3. Dev
    20/01/2012 at 17:46 | #3

    This is not a blur, it’s a basic alpha gradient. Useless article…

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.