To keep our application code separate from our menu layout information, Android uses a designated resource folder (res/menu
) and an XML layout file to define the physical appearance of our menu; such as the titles and icons we see in Android pop-up menus. The Activity class contains a callback method, onCreateOptionsMenu()
, that can be overridden to inflate a menu.
Android menus are defined in a specific, designated folder. Eclipse does not create this folder by default so start up a new project and add a new folder inside the res
folder and call it menu
.
Create a new XML file in our new
res/menu
folder and call itmy_menu.xml
. Complete the new file as follows:<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/item_one" android:title="first item" /> <item android:id="@+id/item_two" android:title="second item...