Android 3.0 HoneyComb- Display ActionBar – 1

By -

The ActionBar is a widget for activities that replaces the traditional title bar at the top of the screen. By default, the ActionBar 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.

The ActionBar offers several useful features, including the ability to:

  1. Display items from the Options Menu directly in the Action Bar, as “action items”-providing instant access to key user actions.
  2. 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.
  3. Provide tabs for navigating between fragments.
  4. Provide a drop-down list for navigation.
  5. Provide interactive “action views” in place of action items (such as a search box).

Here is a simple example:

public class actionBarTest extends Activity implements ActionBar.TabListener{
    /** Called when the activity is first created. */

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       ActionBar bar = getActionBar();
       bar.addTab(bar.newTab().setText("Tab 1").setTabListener(this));
       bar.addTab(bar.newTab().setText("Tab 2").setTabListener(this));
       bar.addTab(bar.newTab().setText("Tab 3").setTabListener(this));
       bar.addTab(bar.newTab().setText("Tab 4").setTabListener(this));

       bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
       bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
       bar.setDisplayShowHomeEnabled(true);
       // remove the activity title to make space for tabs
       bar.setDisplayShowTitleEnabled(false);
	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}
}

CEO & Co-Founder at SolGuruz® | Organiser @ GDG Ahmedabad | Top 0.1% over StackOverflow | 15+ years experienced Tech Consultant | Helping startups with Custom Software Development

Loading Facebook Comments ...
Loading Disqus Comments ...