Android Action Bar are used in many applications, it is easy to implement and for consistency in UI design it offers user a familiar interface across applications.
Previous post: Implement the overflow menu
This post give a simple example of how to dynamically change actionbar item text.
The trick is simply use
public boolean onPrepareOptionsMenu (Menu menu)
Which prepare the Screen’s standard options menu to be displayed:
This is called right before the menu is shown, every time it is shown. You can use this method to efficiently enable/disable items or otherwise dynamically modify the contents.
The example code will create a item, and the item title (when there is no icon, item text will be treated as title text) start with 0, every time it is clicked the number will go up.
- by doing so first we create a
- and then set it to a item we want it to be by `find menu item’
here is how the code look like:
to handle the item that has been clicked in onOptionsItemSelected:
Here are screenshots:
Source code on Githubcomments powered by Disqus