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??
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With