1. Create a menu directory in the res directory.
2. Add a file named of mymenu.xml to the menu directory. An item named myItem is created. An icon named ic_menu_add is used, from the default Android platform icons, with a visible text of "My Item"
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/myItem"
android:icon="@android:drawable/ic_menu_add"
android:title="My Item" />
</menu>
3. Compile and run!
4. For more items, you can add more items under the first item, befor the </menu> tag, to the above code. Such as,
<item android:id="@+id/myItem2"
android:icon="@android:drawable/ic_menu_delete"
android:title="My Item 2" />
Next Recommended Article: onCreateOptionsMenu - Create an Options Menu
Resources:
Popular Posts
- android:ellipsize - Add an ellipsis(...) in a TextView
- android:textColorHighlight - Set the Color of Highlighted Text in an EditText
- Perform an Action after Enter keypress on EditText
- How to Register an Activity that Responds to NFC tags for URI's that point to a URL
- How to Import a Library
- Save LogCat to a Text File
- android:alpha - Set the Opacity/Transparency of Text in TextView/EditText
- android:drawablePadding - Add Padding to a Drawable in a TextView, in XML
- How to Set Permission for I/O Operations over NFC
- How to Install an SDK package