Alex Rivera | Logout

Adding Menu in Action Bar

Asked 2011-10-03T05:52:01.870
11

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??

Edit
Report

2 Answers

27

The same way you create regular menus:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.game_menu, menu);
    return true;
}

http://developer.android.com/guide/topics/ui/menus.html#OptionsMenu

answered 2011-10-03T06:16:13.457
2

I know this is a pretty old question, but I'll throw an answer at it anyway. If you're dealing with a Fragment, you'll need to let the system know you'd like to contribute to the action bar or onCreateOptionsMenu will never be called. https://stackoverflow.com/a/10049807/725752

answered 2012-04-25T15:08:10.397

Your Answer