I currently have a SearchView in the action bar of my app. When I click the search icon, the SearchView expands and the keyboard pops up as expecte
To intercept BACK button override onBackPressed() (see docs)
@Override
public void onBackPressed() {
if (isSearchViewVisible) {
SearchView searchView = (SearchView) menu.findItem(R.id.searchBox)
.getActionView();
// This method does not exist
searchView.invokeClose();
} else {
super.onBackPressed();
}
}
EDIT:
Docs say:
If necessary, you can expand or collapse the action view in your own code by calling expandActionView() and collapseActionView() on the MenuItem.