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 searchview to return to its completely collapsed state.
Instead, it shrinks down but stays in a slightly expanded view.
I've thrown EVERYTHING I can find at this thing to close it, but cannot for the life of me get the right method. Here's the function:
final SearchView.OnCloseListener closeListener = new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
return closeSearch();
}
};
protected boolean closeSearch() {
_searchView.clearFocus();
_searchView.setQuery("", false);
_searchView.setFocusable(false);
_searchMenuItem.collapseActionView();
isSearchFragmentVisible(false);
return false;
}
Close search is then manually called when an item is selected from the custom "suggestion" listview.
Returning
false
should have been sufficient based on the latest documentation and the source code ifficonifiedByDefault == true
.Did you by any chance define
iconifiedByDefault="false"
or calledsetIconifiedByDefault(false)
?Instead of calling
_searchView.onActionViewCollapsed()
callmenuItem.collapseActionView()
where_searchView = menuItem.getActionView()
.It works for me.
This worked for me and it also closed the keyboard by Default