There is this widget for the ActionBar which called ‘SearchView’.
When it’s not in use, it looks like this:

And when it’s in use, it looks like this:

I want (programmatically of course) to open the searchview (make it “in use”).
I tried several functions such as:
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setOnQueryTextListener(this);
searchView.performClick();
searchView.requestFocus();
But none of those worked…
The SearchView in the XML:
<item android:id="@+id/menu_search"
android:title="Search"
android:icon="@drawable/ic_action_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
Expand the
SearchViewwithand collapse it with
You need to change the value of
android:showAsActionfromifRoom|collapseActionViewtoalways. TheSearchView‘s attributeandroid:iconifiedByDefaultshould betrue, which is the default value, otherwise the user can not collapse theSearchViewafter it was expanded programmatically.