Contextual Action Bar in Honeycomb

2019-06-21 11:09发布

问题:

I'd like to change my Action Bar buttons in code according to whatever is selected on screen.

This is kind of like the Honeycomb Gmail app, where you can check a few mail items and get a different Action Bar with a different look too.

Any idea how I can do this?

回答1:

To obtain an action bar item, use the getActionBar() method within an activity. Once you have the ActionBar item, you can add and remove tabs using methods from within the ActionBar class.

The setCustomView() and setDisplayOptions() items will help tailor the action bar to a look more to your liking.

To add items to the action bar, you need to add them to the options menu. The action bar corresponds directly to the old menu (onCreateOptionsMenu() menu) of versions below 3.0. Take a look here.