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
- Save LogCat to a Text File
- android:ellipsize - Add an ellipsis(...) in a TextView
- Perform an Action after Enter keypress on EditText
- Intent setType(String type) - How to Set an Explicit MIME data type
- Solution: error: Error parsing XML: unbound prefix
- Cursor getColumnIndex - Get the Index for a Column Name
- Determine the Hex value for a color
- android:textColorHint - Set the Color of Hint Text in TextView/EditText
- android:nextFocusRight - Set the Next Focus Right to a TextView/EditText
- Solution: Running Android Lint has encountered a problem Failed