Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Menu in Action Bar

I have a Action Bar where i want to add one help button using Menu. I am using Android 3.0. My Menu code is like below:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item  
    android:id="@+id/help_btn"
    android:icon="@drawable/help"
    android:title="Help"
    android:showAsAction="ifRoom|withText"
/>

Now how can i add this menu in the action bar??

like image 267
Arindam Mukherjee Avatar asked Oct 03 '11 05:10

Arindam Mukherjee


People also ask

How do I customize my action bar?

This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do you add action items to the action bar?

All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.


1 Answers

Update;

You can inflate a menu like this @override

Put in res/menu/YOUR_MENU.xml

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.YOUR_MENU, menu);
    return true;
}
like image 185
Carlos Reyes Avatar answered Oct 17 '22 12:10

Carlos Reyes