Reputation: 705
I have a search widget on my actionbar but my problem is that when I get back from the result activity the widget is still open. I want it to return on the initial state before I clicked on the actionbar button. I tried on the onSaveInstanceState of the main activity the below code but I doesn't worked. Any ideas?
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
searchView.setQuery("", false);
searchView.clearFocus();
searchView.setIconified(true);
}
Upvotes: 2
Views: 1074
Reputation: 46
Try the below.
onCreateOptionsMenu(Menu menu)
{
MenuItem searchItem = menu.findItem(R.id.yoursearchitem);
}
Call below when you want to close the search item.
searchItem.collapseActionView();
Upvotes: 1
Reputation: 3045
Try with this:
searchView.setIconifiedByDefault(true);
searchView.setFocusable(false);
Upvotes: 3