I have an Android application that employs an ActionBar SearchView
Everything works fine when requesting a search, the search icon expands to allow text entry, the softkeyboard appears, i enter a query string and this is passed to my designated SearchActivity to display the search results.
The problem is that on pressing the back button and returning to the original activity the SearchView is still expanded, and still contains my search query.
I have attempted to call collapseActionView() on the searchMenuItem however this doesn't work.
When i test the menuItem for isActionViewExpanded it returns false.
how do i get the desired behaviour?
Why doesnt collapseActionView() close SearchView
903 views Asked by Hector At
2
There are 2 answers
0
On
The real reason is that there is an extra toolbar inside.
When back pressed, another toolbar instance is used, and the member is null, resulting in unsuccessful subsequent callbacks.
So the solution is very simple. You can directly call the collapseActionView method of the toolbar of the current activity.
mToolbar.collapseActionView();
Try this: