billiout
billiout

Reputation: 705

Android: Search widget clearFocus() not working

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

Answers (2)

John Li
John Li

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

Carlos J
Carlos J

Reputation: 3045

Try with this:

        searchView.setIconifiedByDefault(true);
        searchView.setFocusable(false);

Upvotes: 3

Related Questions