Menus offer a way to expose application functions without sacrificing valuable screen space. Each Activity can specify its own menu that’s displayed when the device’s menu button is pressed. Android also supports context menus that can be assigned to any View. Context menus are normally triggered when a user holds the middle D-pad button, depresses the trackball, or long-presses the touchscreen for around three seconds when the View has focus.
Activity and context menus support submenus, checkboxes, radio buttons, shortcut keys, and icons.
To improve the usability of application menus, Android features a three-stage menu system optimized
for small screens:
-The icon menu appears along the bottom of the screen when the menu button is pressed. It displays the icons and text for a limited number of Menu Items (typically six). This icon menu does not display checkboxes, radio buttons, or the shortcut keys for MenuItems.
If the Activity menu contains more than the maximum number of visible Menu Items, a More Menu Item is displayed. When selected, it displays the expanded menu. Pressing the back button closes the icon menu.
-The expanded menu The expanded menu is triggered when a user selects the More Menu Item from the icon menu. It displays a scrollable list of only theMenu Items that weren’t visible in the icon menu. This menu displays full text, shortcut keys, and checkboxes/radio buttons. It does not, however, display icons. Pressing back from the expanded menu returns you to the icon menu.
Submenus The traditional expanding hierarchical tree can be awkward to navigate using a mouse, so it’s no surprise that this metaphor is particularly ill-suited for use on mobile devices. The Android
alternative is to display each submenu in a floating window.
Since Android does not support nested submenus, you can’t add a submenu to a submenu. As with the extended menu, icons are not displayed in the submenu.
Defining a menu in XML
<menu xmlns:android="http://schemas.android.com/apk/res/android" android:name="Context Menu">
<item android:id="@+id/item01" android:icon="@drawable/menu_item" android:title="Item 1">
</item>
<item android:id="@+id/item02" android:checkable="true" android:title="Item 2">
</item>
<item android:id="@+id/item03" android:numericShortcut="3" android:alphabeticShortcut="3"
android:title="Item 3">
</item>
<item android:id="@+id/item04" android:title="Submenu">
<menu>
<item android:id="@+id/item05" android:title="Submenu Item">
</item>
</menu>
</item>
</menu>
To use your Menu resource, use the MenuInflator class within your onCreateOptionsMenu or onCreateContextMenu event handlers. Inflating an XML menu resource:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
menu.setHeaderTitle("Context Menu");
}
Activity and context menus support submenus, checkboxes, radio buttons, shortcut keys, and icons.
To improve the usability of application menus, Android features a three-stage menu system optimized
for small screens:
-The icon menu appears along the bottom of the screen when the menu button is pressed. It displays the icons and text for a limited number of Menu Items (typically six). This icon menu does not display checkboxes, radio buttons, or the shortcut keys for MenuItems.
If the Activity menu contains more than the maximum number of visible Menu Items, a More Menu Item is displayed. When selected, it displays the expanded menu. Pressing the back button closes the icon menu.
-The expanded menu The expanded menu is triggered when a user selects the More Menu Item from the icon menu. It displays a scrollable list of only theMenu Items that weren’t visible in the icon menu. This menu displays full text, shortcut keys, and checkboxes/radio buttons. It does not, however, display icons. Pressing back from the expanded menu returns you to the icon menu.
Submenus The traditional expanding hierarchical tree can be awkward to navigate using a mouse, so it’s no surprise that this metaphor is particularly ill-suited for use on mobile devices. The Android
alternative is to display each submenu in a floating window.
Since Android does not support nested submenus, you can’t add a submenu to a submenu. As with the extended menu, icons are not displayed in the submenu.
Defining a menu in XML
<menu xmlns:android="http://schemas.android.com/apk/res/android" android:name="Context Menu">
<item android:id="@+id/item01" android:icon="@drawable/menu_item" android:title="Item 1">
</item>
<item android:id="@+id/item02" android:checkable="true" android:title="Item 2">
</item>
<item android:id="@+id/item03" android:numericShortcut="3" android:alphabeticShortcut="3"
android:title="Item 3">
</item>
<item android:id="@+id/item04" android:title="Submenu">
<menu>
<item android:id="@+id/item05" android:title="Submenu Item">
</item>
</menu>
</item>
</menu>
To use your Menu resource, use the MenuInflator class within your onCreateOptionsMenu or onCreateContextMenu event handlers. Inflating an XML menu resource:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
menu.setHeaderTitle("Context Menu");
}
No comments:
Post a Comment