Action Bar

The project describes How to implement Action Bar for your application. 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.

Underlying Algorithm:

Basic description of algorithm in step by step form:

1.) Create a Project ActionBarExample
2.) Create and open the res/layout/main.xml file and insert the following:

	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent" android:background="#81BEF7"
			android:id="@+id/buttonlayout" android:orientation="horizontal"
		android:layout_width="fill_parent" android:layout_height="wrap_content"
		android:height="32dp" android:gravity="left|top" android:background="#2B60DE"
		android:paddingTop="2dp" android:paddingBottom="2dp">
					android:id="@+id/buttonlayout2" android:orientation="horizontal"
			android:layout_height="wrap_content" android:gravity="left|center_vertical"
			android:layout_gravity="left" android:layout_width="wrap_content">
							android:layout_width="32dp" android:layout_height="32dp"
				android:background="@drawable/icon" />
							android:layout_height="fill_parent" android:textStyle="bold"
				android:text="SimpleActionBar" android:textColor="#FFFFFF"
				android:textSize="15sp" android:gravity="center_vertical"
				android:paddingLeft="5dp" />
							android:id="@+id/buttonlayout2" android:orientation="horizontal"
				android:layout_height="wrap_content" android:gravity="right"
				android:layout_gravity="right" android:layout_width="fill_parent">
									android:layout_width="32dp" android:layout_height="32dp"
					android:background="@drawable/ea" />
									android:layout_width="32dp" android:layout_height="32dp"
					android:background="@drawable/icon" />
					android:layout_gravity="left" android:scrollbars="horizontal|vertical"
			android:layout_height="wrap_content" android:layout_width="fill_parent"
							android:layout_height="wrap_content" android:layout_width="match_parent" />

3.) Make sure to add following in your manifest file:


“android:theme=”@android:style/Theme.NoTitleBar” will enable application to popup as action bar.

4.) Run the application.

Steps to Create:

1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. ActionBarExample Enter following information:
Project name: ActionBarExample
Build Target: Android 2.3.3
Application name: ActionBarExample
Package name: org.example. ActionBarExample
Create Activity: ActionBarExample

On Clicking Finish ActionBarExample code structure is generated with the necessary Android Packages being imported along with Following code must be added in ActionBarExample class to get the menu to work.

    public void onCreate(Bundle savedInstanceState) {

Output –The final output:

About the Author

Leave a Reply 4 comments

Felipe Marques - November 24, 2011 Reply

thank you so much! You do not know if it helped me!

fermenter - December 1, 2011 Reply

does not work, project has errors with regard to @drawable/icon

hash - February 14, 2012 Reply

nice article

Unknown - March 2, 2012 Reply

This is very well. I love it.

Leave a Reply: