Theaction bar(Action Bar) is located at the top of
the activity. It can display the activity title, icon, actions which can be
triggered, additional views and other interactive items. It can also be used
for navigation in your application.

The action bar is enabled for
devices which specify a target SDK of API version 11 or higher. It is possible
to disable the action bar via the used theme, but the default Android themes
have it enabled.

1.Create
an Android project and minimum api must be greater than 13

2.Add
menu item in main menu

<menuxmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

tools:context=".MainActivity">

<item

android:id="@+id/action_search"

android:icon="@android:drawable/ic_menu_search"

android:showAsAction="ifRoom"

android:title="@string/action_search"/>

<item

android:id="@+id/action_record"

android:icon="@android:drawable/btn_star_big_on"

android:showAsAction="ifRoom"

android:title="@string/action_fav"/>

<item

android:id="@+id/action_save"

android:icon="@android:drawable/ic_btn_speak_now"

android:showAsAction="ifRoom"

android:title="@string/action_rec"/>

<item

android:id="@+id/action_label"

android:icon="@android:drawable/ic_menu_camera"

android:showAsAction="ifRoom"

android:title="@string/action_Camera"/>

<item

android:id="@+id/action_play"

android:icon="@android:drawable/ic_menu_call"

android:showAsAction="ifRoom"

android:title="@string/action_Call"/>

<item

android:id="@+id/action_play2"

android:icon="@drawable/ic_launcher"

android:showAsAction="ifRoom"

android:title="@string/action_emergrncy"/>

</menu>

3.Add
String name in res/values/string.xml

<?xmlversion="1.0"encoding="utf-8"?>

<resources>

<stringname="app_name">ActionBarTest</string>

<stringname="action_settings">Settings</string>

<stringname="action_search">Search</string>

<stringname="action_fav">Favorites</string>

<stringname="action_rec">Recording</string>

<stringname="action_Camera">Camera</string>

<stringname="action_Call">Phone Call</string>

<stringname="action_emergrncy">Emergency</string>

<stringname="hello_world">Hello world!</string>

</resources>

4.Add
following code in MainActivity.class

package com.example.actionbartest;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

publicclass MainActivity extends Activity {

@Override

protectedvoid onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

publicboolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

returntrue;

}}

Now run your application

If you want to split
your action bar then add following code in AndroidManifest.xml
file