1. Menu
Three fundamental types of menus or action presentation on all versions of Android:
<1>Option menu and action bar
Android 2.3 or lower, reveal the options menu panel by pressing MEnu button
Android 3.0 or higher, options menu are presented by the action bar as a combination of on-screen action items and overflow options
<2>Context menu and contextual action mode
floating menu that appears when user performs a long_click on an element
<3>Popup menu
displays a list of items in a vertical list that‘s anchored to the view that invoked the menu.
2. Defining a Menu in XML
define a menu and all its items in an XML menu resource. then inflate the menu resource(load it as a Menu object) in activity or fragment
<menu> a container for menu items.
<item> a single item in a menu
This element may contain a nested <menu> element in order to create a submenu.
<group> invisible container for <item> elements
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> // File menu <item android:id="@+id/file" android:title="@string/file" > <!-- "file" submenu --> <menu> <item android:id="@+id/create_new" android:title="@string/create_new" /> <item android:id="@+id/open" android:title="@string/open" /> </menu> </item> // Edit Menu <item android:id="@+id/edit" .......> </menu>
3. Creating an options Menu
Android 2.3 or lower. the contents of your options menu appear at the bottom of the screen when the user presses the Menu button,
Android 3.0 and higher, items from the options menu are available in the action bar.
By default, the system places all items in the action overflow, which the user can reveal with the action overflow icon on the right side
of the action bar
To enable quick access to important actions, you can promote a few items to appear in the action bar by adding
android:showAsAction="ifRoom" to the corresponding <item> elements