Android action bar: press the Up soft key

Hi
Android 4 (ICS) offers an element of the type ActionBar. Using an ActionBar, I created a search widget in which I can enter text to trigger a remote search. If you click on the magnifying glass icon in this ActionBar to open the text field of the search widget, two things will happen:

  • The on-screen keyboard is displayed.
  • The home button (application icon in the upper left corner) changes its functionality of the up button. "up" means that you undo your last action (in this case: opening the text field of the search widget)

If you press the up button, the search widget will crash to make the text box disappear. At the same time, the up button changes its functionality to act as a home button. This behavior describes the default behavior of an Android 4 ActionBar with an attached search widget.

Using the hardware back button instead of the soft up button, the keyboard disappears, but the search widget remains open. Also, the up button does not change to the home button.

My question is: How can I launch the up button in an ActionBar software application? If I could do this, I could collapse the text field of the search widget and return the up button to become the home button again if the user clicks the back button of the equipment.

This example displays the home button on the left and the closed search widget "magnifier icon" on the right. If the user clicks on the magnifying glass, a text box appears and the "home" button becomes the "up" button.

Thanks in advance!

enter image description here

+4
source share
3 answers

I think there might be a solution for this. As the documentation says,

To jump when the user clicks the application icon, you can use the static method of the NavUtils class, navigateUpFromSameTask ().

So you can manually call

NavUtils.navigateUpFromSameTask(this); 

To execute the home button, press soft.

+1
source

I counted the network and SO, and cannot find a way to run this programmatically. I ended up just recreating the bits and pieces needed to switch the view to the home view, as well as changing the action bar in normal mode and putting it in an open method so that other classes can return to viewing.

0
source

You can trigger a click on any view programmatically by calling performClick() in the View .

See the documentation for performClick() .

-1
source

Source: https://habr.com/ru/post/1390854/


All Articles