| android.view.Menu |
Interface for managing the items in a menu.
By default, every Android Activity supports a popup menu of actions or options. You can add items to this menu and handle clicks on your additions. Menu items also support check marks.
Nested Classes| Menu.Item | Interface for direct access to a previously created menu item. |
| Menu.OnClickListener | Interface to find out when a menu item is invoked. |
| Menu.OnSelectionListener | Interface to find out when the selection state of a menu item changes. |
Known Indirect Subclasses| Value | ||||
|---|---|---|---|---|
| int | ALTERNATIVE | Category code for menu group and identifier integers that are alternative actions on the data that is currently displayed -- or/add this with your base value. | 262144 | 0x00040000 |
| int | APPEND_TO_GROUP | Flag for addIntentOptions(int, int, ComponentName, Intent[], Intent, int, Menu.Item[]): if set, do not automatically remove any existing menu items in the same group. | 1 | 0x00000001 |
| int | CATEGORY_MASK | This is the part of a menu group or identifier integer that supplies the category of the item. | -65536 | 0xffff0000 |
| int | CATEGORY_SHIFT | Bit shift of the category portion of the group/identifier integer. | 16 | 0x00000010 |
| int | CONTAINER | Category code for menu group and identifier integers that are part of a container -- or/add this with your base value. | 65536 | 0x00010000 |
| int | FIRST | First value for group and identifier integers, for normal menu items that do not have a category. | 1 | 0x00000001 |
| int | NONE | Value to use for group and identifier integers when you don't care about them. | 0 | 0x00000000 |
| int | PERFORM_NO_CLOSE | Flag for performShortcut(int, KeyEvent, int): if set, do not close the menu after executing the shortcut. | 1 | 0x00000001 |
| int | SECONDARY | Category code for menu group and identifier integers that are user-supplied secondary (infrequently used) options -- or/add this with your base value. | 196608 | 0x00030000 |
| int | SELECTED_ALTERNATIVE | Category code for menu group and identifier integers that are alternative actions on the item that is currently selected -- or/add this with your base value. | 327680 | 0x00050000 |
| int | SYSTEM | Category code for menu group and identifier integers that are provided by the system -- or/add this with your base value. | 131072 | 0x00020000 |
| int | USER_MASK | This is the part of a menu group or identifier integer that the user can provide. | 65535 | 0x0000ffff |
| int | USER_SHIFT | Bit shift of the user portion of the group/identifier integer. | 0 | 0x00000000 |
| Item | add(int group, int id, CharSequence title, Runnable callback) | ||||
| Add a new item to the menu. | |||||
| Item | add(int group, int id, CharSequence title, int iconRes) | ||||
| Add a new item to the menu. | |||||
| Item | add(int group, int id, int titleRes, int iconRes) | ||||
| Add a new item to the menu. | |||||
| Item | add(int group, int id, CharSequence title) | ||||
| Add a new item to the menu. | |||||
| Item | add(int group, int id, int titleRes) | ||||
| Variation on add(int, int, CharSequence) that takes a string resource identifier instead of the string itself. | |||||
| Item | add(int group, int id, int titleRes, Runnable callback) | ||||
| Variation on add(int, int, CharSequence, Runnable) that takes a string resource identifier instead of the string itself. | |||||
| int | addIntentOptions(int group, int id, ComponentName caller, Intent[] specifics, Intent intent, int flags, Item[] outSpecificItems) | ||||
| Add a group of menu items corresponding to actions that can be performed for a particular Intent. | |||||
| SubMenu | addSubMenu(int group, int id, CharSequence title) | ||||
| Add a new sub-menu to the menu. | |||||
| SubMenu | addSubMenu(int group, int id, CharSequence title, int iconRes) | ||||
| Add a new sub-menu to the menu. | |||||
| SubMenu | addSubMenu(int group, int id, int titleRes, int iconRes) | ||||
| Variation on addSubMenu(int, int, CharSequence) that takes a string resource identifier for the title instead of the string itself and a resource identifier for the icon. | |||||
| SubMenu | addSubMenu(int group, int id, int titleRes, Drawable icon) | ||||
| Variation on addSubMenu(int, int, CharSequence) that takes a string resource identifier for the title instead of the string itself, and a Drawable for the icon. | |||||
| SubMenu | addSubMenu(int group, int id, int titleRes) | ||||
| Variation on addSubMenu(int, int, CharSequence) that takes a string resource identifier for the title instead of the string itself. | |||||
| SubMenu | addSubMenu(int group, int id, CharSequence title, Drawable icon) | ||||
| Add a new sub-menu to the menu. | |||||
| void | clear() | ||||
| Remove all existing items from the menu, leaving it empty as if it had just been created. | |||||
| int | findGroupIndex(int group) | ||||
| Get the index of the first menu item that is in the given group. | |||||
| Item | findItem(int id) | ||||
| Return the menu item with a particular identifier. | |||||
| int | findItemIndex(int id) | ||||
| Get the index of a menu item that has the given identifier. | |||||
| Item | get(int index) | ||||
| Retrieve the menu item object at a particular index. | |||||
| boolean | hasShownItems() | ||||
| Return whether the menu currently has item items that are being shown. | |||||
| boolean | isShortcutKey(int keyCode, KeyEvent event) | ||||
| Is a keypress one of the defined shortcut keys for this window. | |||||
| boolean | performIdentifierAction(int id, int flags) | ||||
| Execute the menu item action associated with the given menu identifier. | |||||
| boolean | performShortcut(int keyCode, KeyEvent event, int flags) | ||||
| Execute the menu item action associated with the given shortcut character. | |||||
| void | removeGroup(int group) | ||||
| Remove all items in the given group. | |||||
| void | removeItem(int id) | ||||
| Remove the item with the given identifier. | |||||
| void | removeItemAt(int index) | ||||
| Remove the item at the given index. | |||||
| void | setDefaultItem(int id) | ||||
| Set the item that is initially selected when the menu is displayed. | |||||
| void | setGroupCheckable(int group, boolean checkable, boolean exclusive) | ||||
| Control whether a particular group of items can show a check mark. | |||||
| void | setGroupShown(int group, boolean shown) | ||||
| Show or hide all menu items that are in the given group. | |||||
| void | setItemCheckable(int id, boolean checkable) | ||||
| Control whether a particular item with the given identifier can display a check mark. | |||||
| void | setItemChecked(int id, boolean checked) | ||||
| Show or hide the check mark for a particular menu item selected by its identifier. | |||||
| void | setItemShown(int id, boolean shown) | ||||
| Show or hide a particular menu item selected by its identifier. | |||||
| void | setQwertyMode(boolean isQwerty) | ||||
| Control whether the menu should be running in qwerty mode (alphabetic shortcuts) or 12-key mode (numeric shortcuts). | |||||
| int | size() | ||||
| Get the number of items in the menu. | |||||
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| title | The text to display for the item. |
| callback | The object to invoke when the item is selected. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| title | The text to display for the item. |
| iconRes | The resource ID of the icon for the item. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| titleRes | The resource ID of the text to display for the item. |
| iconRes | The resource ID of the icon for the item. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| title | The text to display for the item. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| titleRes | Resource identifier of title string. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| titleRes | Resource identifier of title string. |
| callback | The object to invoke when the item is selected. |
See queryIntentActivityOptions(ComponentName, Intent[], Intent, int) for more * details on the caller, specifics, and intent arguments. The list returned by that function is used to populate the resulting menu items.
All of the menu items of possible options for the intent will be added with the given group and id. You can use the group to control ordering of the items in relation to other items in the menu. Normally this function will automatically remove any existing items in the menu in the same group and place a divider above and below the added items; this behavior can be modified with the flags parameter. For each of the generated items setIntent(Intent) is called to associate the appropriate Intent with the item; this means the activity will automatically be started for you without having to do anything else.
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| caller | The current activity component name as defined by queryIntentActivityOptions(). |
| specifics | Specific items to place first as defined by queryIntentActivityOptions(). |
| intent | Intent describing the kinds of items to populate in the list as defined by queryIntentActivityOptions(). |
| flags | Additional options controlling how the items are added. |
| outSpecificItems | Optional array in which to place the menu items that were generated for each of the specifics that were requested. Entries may be null if no activity was found for that specific action. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| title | The text to display for the item. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| title | The text to display for the item. |
| iconRes | The new icon (as a resource ID) to be displayed. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| titleRes | Resource identifier of title string. |
| iconRes | The new icon (as a resource ID) to be displayed. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| titleRes | Resource identifier of title string. |
| icon | The new icon (as a Drawable) to be displayed. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| titleRes | Resource identifier of title string. |
| group | Item ordering grouping control. The item will be added after all other items whose order is <= this number, and before any that are larger than it. This can also be used to define groups of items for batch state changes. Normally use 0. |
|---|---|
| id | Unique item ID. Use 0 if you do not need a unique ID. |
| title | The text to display for the item. |
| icon | The new icon (as a Drawable) to be displayed. |
| group | The group to find. |
|---|
| id | The identifier to find. |
|---|
| id | The identifier to find. |
|---|
| index | The index of the desired item. |
|---|
| id | Identifier associated with the menu item. |
|---|---|
| flags | Additional option flags or 0. |
| keyCode | The keycode of the shortcut key. |
|---|---|
| event | Key event message. |
| flags | Additional option flags or 0. |
| group | The group to be removed. If there are no items in this group, nothing happens. |
|---|
| id | The item to be removed. If there is no item with this identifier, nothing happens. |
|---|
| index | The index of the item to be removed. If this index is invalid an exception is thrown. |
|---|
| id | The identifier of the menu item to select. Supply -1 to cleat the default item. |
|---|
| group | The group of items to operate on. |
|---|---|
| checkable | Set to true to allow a check mark, false to disallow. The default is false. |
| exclusive | If set to true, only one item in this group can be checked at a time; checking an item will automatically uncheck all others in the group. If set to false, each item can be checked independently of the others. |
| group | The group of items to operate on. |
|---|---|
| shown | If true the items are shown, else they are hidden. |
| id | The menu item to operate on. |
|---|---|
| checkable | Set to true to allow a check mark, false to disallow. The default is false. |
| id | The menu item to operate on. |
|---|---|
| checked | Set to true to display a check mark, false to hide it. The default value is false. |
| id | The menu item to operate on. |
|---|---|
| shown | If true the item is shown, else it is hidden. |
| isQwerty | If true the menu will use alphabetic shortcuts; else it will use numeric shortcuts. |
|---|