Creating an Options menu
Before we actually create and display a menu, let's look at a menu to see the end result. The following is a screenshot showing the menu section of Chrome:
The most obvious feature to note is that the menu will look different based on the screen size. By default, menu items will be added to the Overflow menu—that's the menu you see when you press the three dots at the far right edge.
Menus are typically created in resource files using XML
(like many other Android resources) but they are stored in the res/menu
directory though they can also be created in code. To create a menu resource, use the <menu>
element as shown:
<menu xmlns:android="http://schemas.android.com/apk/res/android"> </menu>
The <item>
element defines each individual menu item and is enclosed in the <menu>
element. A basic menu item looks as follows:
<item android:id="@+id/settings" android:title="@string/settings"...