Saturday, April 28, 2012

Action Bar with Tabs in Android

The Action Bar is a widget for activities that replaces the traditional title bar at the top of the screen. By default, the Action Bar includes the application logo on the left side, followed by the activity title, and any available items from the Options Menu on the right side.


·      Display items from the Options Menu directly in the Action Bar, as "action items"—providing instant access to key user actions.
·      Menu items that do not appear as action items are placed in the overflow menu, revealed by a drop-down list in the Action Bar.
·      Provide tabs for navigating between fragments.
·      Provide a drop-down list for navigation.
·      Provide interactive "action views" in place of action items (such as a search box).


Step - 1: Get access of Action Bar
final ActionBar actionBar = getActionBar();
Step - 2 Create a class MyActionBarListener which implements ActionBar.TabListener to set action on tab.
private class MyActionBarListener implements ActionBar.TabListener {
Step - 3: Add tab to Action Bar. (You can add multiple tab)
actionBar.addTab(actionBar.newTab().setText("Tab 1").setTabListener(new MyActionBarListener()));
Step - 4: After adding all tabs, set setNavigationMode(...) to Action Bar.
Step - 5: Run Application

No comments:

Post a Comment