If you want to have it iconifiedByDefault
, this worked for me. setFocusable
and setIconified
are needed.
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setIconifiedByDefault(true);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
Update: If you are Using android.support.v7.widget.SearchView
the behaviour us very different. clearFocus
is needed if you don't want the keyboard pop-up all the time. For some reason the menu is recreated all the time, when using appcompat.
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setIconified(false);
searchView.clearFocus();