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
- Perform an Action after Enter keypress on EditText
- android:ellipsize - Add an ellipsis(...) in a TextView
- Intent setType(String type) - How to Set an Explicit MIME data type
- Create a Drawable Object Variable
- How to Register an Activity that Responds to NFC tags for URI's that point to a URL
- Solution: Running Android Lint has encountered a problem Failed
- android:alpha - Set the Opacity/Transparency of Text in TextView/EditText
- MenuInflater - How to Inflate a Menu
- How to Declare a new HttpURLConnection
- android:scrollbarStyle - Change the Scrollbar Location/Style in a TextView