2

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);
}
billiout
  • 695
  • 1
  • 8
  • 22

2 Answers2

3

Try with this:

        searchView.setIconifiedByDefault(true);
        searchView.setFocusable(false);
Carlos J
  • 2,965
  • 4
  • 17
  • 28
1

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();
John Li
  • 46
  • 3