Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset action bar after using SearchView

I'm using SearchView widget to enable searching in my app. After the initial click on the search icon, the SearchView widget expands into the search field and the "back" arrow is shown next to the application icon. If I click the application icon the action bar reverts to the initial state (no "back" arrow) and the SearchView reverts back to icon.

Now the problem: after the search is executed the action bar doesn't change, the only way to revert is to click the application icon or phone's "back" arrow. Not good since I want the action bar go to the initial state when the search is done. I tried SearchView.setIconofied(true) but there are 2 problems:

  1. Search icon appears at the same spot as the edit field (originally it's on the far right).
  2. Action bar still displays "back" arrow.

I think the problem I'm facing results from deviating from the regular navigation pattern. In my case everything is happening inside the same activity (search results are displayed in the same activity that hosts the action bar), so for example executing Activity.finish() simply makes app exit.

How do I trigger "go back one step" of the action bar? Or simulate click on the application icon?

like image 655
Bostone Avatar asked May 02 '12 18:05

Bostone


1 Answers

It sounds like you've set this up as a collapsible action view on a MenuItem. You can call collapseActionView() on that MenuItem instance to send it back to its closed state.

like image 110
adamp Avatar answered Nov 16 '22 14:11

adamp