I\'ve been struggling with this for weeks.. I have a global search that offers up a custom listview with suggestions as a user types. When a user selects an option, I want the s
If you're using Toolbar (android.support.v7.widget.Toolbar) and the corresponding SearchView (android.support.v7.widget.SearchView) with it, this works:
searchView.setQuery("", false);
searchView.clearFocus();
searchView.setIconified(true);
searchView.setIconified(true); // Call this twice
searchView.setIconified(true);
It works for me.
This worked for me and it also closed the keyboard by Default
MenuItemCompat.collapseActionView(menuItem);
Instead of calling _searchView.onActionViewCollapsed()
call menuItem.collapseActionView()
where _searchView = menuItem.getActionView()
.
Found it. The call should be _searchView.onActionViewCollapsed()
. Why on earth you call a "listener" style method (ie, one that begins with 'on') is beyond me.
You should clear the search, remove the focus and then call:
searchView.setIconified(true);