android – Force action Bar show search view-ThrowExceptions

Exception or error:

I am able to expand search view by action like this

<item android:id="@+id/menu_search"
          android:actionViewClass="android.widget.SearchView" />

But i have a 3-tab activity and i’d like to SearchView be always expanded
How may I do that?

How to solve:

Two steps are necessary.

First, you have to make sure your search menu item is always shown as an action and never moved into the overflow menu. To achieve this set the search menu item’s showAsAction attribute to always:

    android:actionViewClass="android.widget.SearchView" />

Second, make sure the action view is not shown in iconified (i.e. collapsed) mode by default. To do this call setIconifiedByDefault(false) on your search view instance:

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(, menu);

    MenuItem searchViewItem = menu.findItem(;
    SearchView searchView = (SearchView) searchViewItem.getActionView();

    return true;

That should do it.

Leave a Reply

Your email address will not be published. Required fields are marked *