---
title: "Action Bar with menu in Android"  
description: "Hi all here we are going to implement Action Bar with menu in Android"  
author: "Manoj Pandey"  
published: 2015-02-20  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1594/action-bar-with-menu-in-android  
category: "android"  
tags: ["android"]  
reading_time: 3 minutes  

---

# Action Bar with menu in Android

Previously, we learn about [Android](https://www.mindstick.com/articles/1567/navigation-drawer-implementation-in-android) [Persistence](https://www.mindstick.com/interview/848/what-is-meant-by-persistence) with Shared Preferences. Now we see how to use Android Persistence with Shared Preferences.\

The action bar (Action Bar) is located at the top of the [activity](https://www.mindstick.com/forum/23119/how-to-save-activity-state-in-android). It can display the activity title, icon, actions which can be triggered, additional views and other [interactive](https://answers.mindstick.com/qa/38931/who-has-won-the-2016-fifa-interactive-world-cup-fiwc) items. It can also be used for [navigation](https://www.mindstick.com/blog/62/different-navigation-in-asp-dot-net) in [your application](https://answers.mindstick.com/qa/95487/how-do-you-troubleshoot-when-your-application-link-is-not-responding).

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](https://yourviews.mindstick.com/story/1788/things-to-ensure-your-construction-project-is-successful) and minimum api must be greater than 13

2. Add [menu item](https://www.mindstick.com/forum/339/highlighting-the-menu-item) in main menu

```
<menu xmlns: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

```
<?xml version="1.0"   encoding="utf-8"?><resources>
    <string name="app_name">ActionBarTest</string>    <string name="action_settings">Settings</string>    <string name="action_search">Search</string>    <string name="action_fav">Favorites</string>    <string name="action_rec">Recording</string>    <string name="action_Camera">Camera</string>    <string name="action_Call">Phone Call</string>    <string name="action_emergrncy">Emergency</string>    <string name="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; 
     public class MainActivity extends Activity { 
     @Override     protected void onCreate(Bundle  savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.activity_main);   
     } 
     @Override     public boolean onCreateOptionsMenu(Menu menu)  {           // Inflate the menu; this adds items to the action bar if it  is present.           getMenuInflater().inflate(R.menu.main, menu);
           return true;
     }} 
```

Now run your application

![Action Bar with menu in Android](https://www.mindstick.com/mindstickarticle/85c75ebc-3233-4bc2-967b-da4225ca7dde/images/4a9372d8-66b5-4daf-bb6c-dff844f50b75.png) ![Action Bar with menu in Android](https://www.mindstick.com/mindstickarticle/85c75ebc-3233-4bc2-967b-da4225ca7dde/images/016ea4ca-0cea-4461-8117-db63393696a8.png)

If you want to split your action bar then add following code in [AndroidManifest.xml](https://www.mindstick.com/interview/12768/what-is-the-androidmanifest-xml) file

```
<application          android:allowBackup="true"          android:icon="@drawable/ic_launcher"          android:label="@string/app_name"          android:theme="@style/AppTheme"          android:uiOptions="splitActionBarWhenNarrow"   >         <!-- For support less than 14 api -->        <meta-data              android:name="android.support.UI_OPTIONS"              android:value="splitActionBarWhenNarrow"   />

```

And run your application

![Action Bar with menu in Android](https://www.mindstick.com/mindstickarticle/85c75ebc-3233-4bc2-967b-da4225ca7dde/images/f1d3a98f-1e60-4171-8cd7-3d3771415b92.png) ![Action Bar with menu in Android](https://www.mindstick.com/mindstickarticle/85c75ebc-3233-4bc2-967b-da4225ca7dde/images/f4fd2bbd-4a20-4b13-ad75-f372119a4051.png)

---

Original Source: https://www.mindstick.com/articles/1594/action-bar-with-menu-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
