android.widget.MenuBuilder
Implementation of the Menu interface for creating a
standard menu UI.
Nested Classes
Known Direct Subclasses
| SubMenuBuilder |
The model for a sub menu, which is an extension of the menu. |
Summary
Constants
| |
|
|
Value |
|
| int |
NUM_TYPES |
The number of different menu types |
4 |
0x00000004 |
| int |
TYPE_CONTEXT |
The menu type that represents the context menu view |
3 |
0x00000003 |
| int |
TYPE_EXPANDED |
The menu type that represents the expanded menu view |
1 |
0x00000001 |
| int |
TYPE_ICON |
The menu type that represents the icon menu view |
0 |
0x00000000 |
| int |
TYPE_SUB |
The menu type that represents the sub menu view |
2 |
0x00000002 |
Constants inherited
from interface
android.view.Menu
ALTERNATIVE,
APPEND_TO_GROUP,
CATEGORY_MASK,
CATEGORY_SHIFT,
CONTAINER,
FIRST,
NONE,
PERFORM_NO_CLOSE,
SECONDARY,
SELECTED_ALTERNATIVE,
SYSTEM,
USER_MASK,
USER_SHIFT
| |
|
|
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 |
Public Constructors
Public Methods
| |
|
|
|
Item |
add(int group, int id, CharSequence title, Runnable callback) |
| |
|
|
|
Item |
add(int group, int id, CharSequence title, int iconResId) |
| |
|
|
|
Item |
add(int group, int id, int titleRes, int iconResId) |
| |
|
|
|
Item |
add(int group, int id, CharSequence title) |
| |
|
|
|
Item |
add(int group, int id, int title) |
| |
|
|
|
Item |
add(int group, int id, int title, Runnable callback) |
| |
|
|
|
int |
addIntentOptions(int group, int id, ComponentName caller, Intent[] specifics, Intent intent, int flags, Item[] outSpecificItems) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, CharSequence title) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, CharSequence title, int iconRes) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, int titleRes, int iconRes) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, int titleRes, Drawable icon) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, int title) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, CharSequence title, Drawable icon) |
| |
|
|
|
void |
clear() |
| |
|
|
|
void |
clearMenuViews() |
| |
|
|
|
int |
findGroupIndex(int group) |
| |
|
|
|
Item |
findItem(int id) |
| |
|
|
|
int |
findItemIndex(int id) |
| |
|
|
|
Item |
get(int index) |
| |
|
|
|
View |
getMenuView(int menuType, ViewGroup parent, boolean createIfNonexistent) |
| |
|
|
|
boolean |
hasShownItems() |
| |
|
|
|
boolean |
isShortcutKey(int keyCode, KeyEvent event) |
| |
|
|
|
boolean |
isShortcutsShown() |
| |
|
|
|
boolean |
performIdentifierAction(int id, int flags) |
| |
|
|
|
boolean |
performShortcut(int keyCode, KeyEvent event, int flags) |
| |
|
|
|
void |
removeGroup(int group) |
| |
|
|
|
void |
removeItem(int id) |
| |
|
|
|
void |
removeItemAt(int index) |
| |
|
|
|
void |
setCallback(Callback callback) |
| |
|
|
|
void |
setCurrentMenuInfo(Object menuInfo) |
| |
|
|
|
void |
setDefaultItem(int id) |
| |
|
|
|
void |
setGroupCheckable(int group, boolean checkable, boolean exclusive) |
| |
|
|
|
void |
setGroupShown(int group, boolean shown) |
| |
|
|
|
void |
setHeader(int titleRes) |
| |
|
|
|
void |
setHeader(int titleRes, Drawable icon) |
| |
|
|
|
void |
setHeader(int titleRes, int iconRes) |
| |
|
|
|
void |
setHeader(CharSequence title) |
| |
|
|
|
void |
setHeader(View headerView) |
| |
|
|
|
void |
setHeader(CharSequence title, int iconRes) |
| |
|
|
|
void |
setHeader(CharSequence title, Drawable icon) |
| |
|
|
|
void |
setItemCheckable(int id, boolean checkable) |
| |
|
|
|
void |
setItemChecked(int id, boolean checked) |
| |
|
|
|
void |
setItemShown(int id, boolean shown) |
| |
|
|
|
void |
setQwertyMode(boolean isQwerty) |
| |
|
|
|
void |
setShortcutsShown(boolean shortcutsShown) |
| |
|
|
|
int |
size() |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
add,
add,
add,
add,
add,
add,
addIntentOptions,
addSubMenu,
addSubMenu,
addSubMenu,
addSubMenu,
addSubMenu,
addSubMenu,
clear,
findGroupIndex,
findItem,
findItemIndex,
get,
hasShownItems,
isShortcutKey,
performIdentifierAction,
performShortcut,
removeGroup,
removeItem,
removeItemAt,
setDefaultItem,
setGroupCheckable,
setGroupShown,
setItemCheckable,
setItemChecked,
setItemShown,
setQwertyMode,
size
| |
|
|
|
Item |
add(int group, int id, CharSequence title, Runnable callback) |
| |
|
|
|
Item |
add(int group, int id, CharSequence title, int iconRes) |
| |
|
|
|
Item |
add(int group, int id, int titleRes, int iconRes) |
| |
|
|
|
Item |
add(int group, int id, CharSequence title) |
| |
|
|
|
Item |
add(int group, int id, int titleRes) |
| |
|
|
|
Item |
add(int group, int id, int titleRes, Runnable callback) |
| |
|
|
|
int |
addIntentOptions(int group, int id, ComponentName caller, Intent[] specifics, Intent intent, int flags, Item[] outSpecificItems) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, CharSequence title) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, CharSequence title, int iconRes) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, int titleRes, int iconRes) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, int titleRes, Drawable icon) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, int titleRes) |
| |
|
|
|
SubMenu |
addSubMenu(int group, int id, CharSequence title, Drawable icon) |
| |
|
|
|
void |
clear() |
| |
|
|
|
int |
findGroupIndex(int group) |
| |
|
|
|
Item |
findItem(int id) |
| |
|
|
|
int |
findItemIndex(int id) |
| |
|
|
|
Item |
get(int index) |
| |
|
|
|
boolean |
hasShownItems() |
| |
|
|
|
boolean |
isShortcutKey(int keyCode, KeyEvent event) |
| |
|
|
|
boolean |
performIdentifierAction(int id, int flags) |
| |
|
|
|
boolean |
performShortcut(int keyCode, KeyEvent event, int flags) |
| |
|
|
|
void |
removeGroup(int group) |
| |
|
|
|
void |
removeItem(int id) |
| |
|
|
|
void |
removeItemAt(int index) |
| |
|
|
|
void |
setDefaultItem(int id) |
| |
|
|
|
void |
setGroupCheckable(int group, boolean checkable, boolean exclusive) |
| |
|
|
|
void |
setGroupShown(int group, boolean shown) |
| |
|
|
|
void |
setItemCheckable(int id, boolean checkable) |
| |
|
|
|
void |
setItemChecked(int id, boolean checked) |
| |
|
|
|
void |
setItemShown(int id, boolean shown) |
| |
|
|
|
void |
setQwertyMode(boolean isQwerty) |
| |
|
|
|
int |
size() |
Details
Constants
public
static
final
int
NUM_TYPES
The number of different menu types
Constant Value:
4
(0x00000004)
public
static
final
int
TYPE_CONTEXT
The menu type that represents the context menu view
Constant Value:
3
(0x00000003)
public
static
final
int
TYPE_EXPANDED
The menu type that represents the expanded menu view
Constant Value:
1
(0x00000001)
public
static
final
int
TYPE_ICON
The menu type that represents the icon menu view
Constant Value:
0
(0x00000000)
public
static
final
int
TYPE_SUB
The menu type that represents the sub menu view
Constant Value:
2
(0x00000002)
Public Constructors
public
MenuBuilder(Context context)
Public Methods
public
Item
add(int group, int id, CharSequence title, Runnable callback)
Add a new item to the menu. This item displays the given
title for its label and will invoke callback when
it is selected.
public
Item
add(int group, int id, CharSequence title, int iconResId)
Add a new item to the menu. This item displays the given
title for its label. Also displays the given iconRes (which is
converted to a Drawable only when needed).
public
Item
add(int group, int id, int titleRes, int iconResId)
Add a new item to the menu. This item displays the given titleRes
resource for its label. Also displays the given iconRes
(which is converted to a Drawable only when needed).
public
Item
add(int group, int id, CharSequence title)
Add a new item to the menu. This item displays the given
title for its label.
public
Item
add(int group, int id, int title)
public
Item
add(int group, int id, int title, Runnable callback)
public
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. The Intent is most often configured with a
null action, the data that the current activity is working with, and
includes either the
ALTERNATIVE_CATEGORY or
SELECTED_ALTERNATIVE_CATEGORY to find activities that
have said they would like to be included as optional action. You can,
however, use any Intent you want.
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.
public
SubMenu
addSubMenu(int group, int id, CharSequence title)
Add a new sub-menu to the menu. This item displays the given
title for its label. The system will call the activity's
onCreatePanelMenu(int, Menu) callback method with
a
SubMenu object and the id you supply here.
Note that you can only have one level of sub-menus, i.e. you cannnot add
a subMenu to a subMenu: An
UnsupportedOperationException will be
thrown if you try.
public
SubMenu
addSubMenu(int group, int id, CharSequence title, int iconRes)
Add a new sub-menu to the menu. This item displays the given
title
for its label and
iconRes as the icon. The system will call the activity's
onCreatePanelMenu(int, Menu) callback method with a
SubMenu object and the id you supply here. Note that you can only
have one level of sub-menus, i.e. you cannnot add a subMenu to a subMenu:
An
UnsupportedOperationException will be thrown if you try.
public
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.
public
SubMenu
addSubMenu(int group, int id, int title)
Add a new sub-menu to the menu. This item displays the given
title
for its label and
iconRes as the icon. The system will call the activity's
onCreatePanelMenu(int, Menu) callback method with a
SubMenu object and the id you supply here. Note that you can only
have one level of sub-menus, i.e. you cannnot add a subMenu to a subMenu:
An
UnsupportedOperationException will be thrown if you try.
public
void
clear()
Remove all existing items from the menu, leaving it empty as if it had
just been created.
public
void
clearMenuViews()
Clears the cached menu views. Call this if the menu views need to another
layout (for example, if the screen size has changed).
public
int
findGroupIndex(int group)
Get the index of the first menu item that is in the given group. Note
that this index can change any time items are added or removed from the
menu; you should not keep it around. If you want to hold on to an item
for later access, hold on to the Item object.
public
Item
findItem(int id)
Return the menu item with a particular identifier.
public
int
findItemIndex(int id)
Get the index of a menu item that has the given identifier. Note that
this index can change any time items are added or removed from the
menu; you should not keep it around. If you want to hold on to an item
for later access, hold on to the Item object.
public
Item
get(int index)
Retrieve the menu item object at a particular index. Use with
findItemIndex() and size().
public
View
getMenuView(int menuType, ViewGroup parent, boolean createIfNonexistent)
Gets a menu View that contains this menu's items.
Parameters
| menuType
| The type of menu to get a View for (must be one of
TYPE_ICON, TYPE_EXPANDED,
TYPE_SUB, TYPE_CONTEXT). |
| parent
| The ViewGroup that provides a set of LayoutParams values
for this menu view |
| createIfNonexistent
| If the menu View hasn't been created before,
create and return the menu View (true), or return null (false) |
Returns
- A View for the menu of type menuType
public
boolean
hasShownItems()
Return whether the menu currently has item items that are being shown.
public
boolean
isShortcutKey(int keyCode, KeyEvent event)
Is a keypress one of the defined shortcut keys for this window.
public
boolean
isShortcutsShown()
Returns
- Whether shortcuts should be shown on menus.
public
boolean
performIdentifierAction(int id, int flags)
Execute the menu item action associated with the given menu identifier.
public
boolean
performShortcut(int keyCode, KeyEvent event, int flags)
Execute the menu item action associated with the given shortcut
character.
public
void
removeGroup(int group)
Remove all items in the given group.
public
void
removeItem(int id)
Remove the item with the given identifier.
public
void
removeItemAt(int index)
Remove the item at the given index.
public
void
setCallback(Callback callback)
public
void
setCurrentMenuInfo(Object menuInfo)
Sets the current menu info that is set on all items added to this menu
(until this is called again with different menu info, in which case that
one will be added to all subsequent item additions).
Parameters
| menuInfo
| The extra menu information to add.
|
public
void
setDefaultItem(int id)
Set the item that is initially selected when the menu is displayed.
public
void
setGroupCheckable(int group, boolean checkable, boolean exclusive)
Control whether a particular group of items can show a check mark. This
is similar to calling
setCheckable(boolean) on all of the menu items
with the given group identifier, but in addition you can control whether
this group contains a mutually-exclusive set items. This should be called
after the items of the group have been added to the menu.
public
void
setGroupShown(int group, boolean shown)
Show or hide all menu items that are in the given group.
public
void
setHeader(int titleRes)
Sets the header of the context menu to the title given in titleRes
resource identifier.
public
void
setHeader(int titleRes, Drawable icon)
Sets the header of the context menu to the title given in
titleRes
resource identifier and the icon given in
icon Drawable.
public
void
setHeader(int titleRes, int iconRes)
Sets the header of the context menu to the title given in titleRes
resource identifier and the icon given in iconRes resource id.
public
void
setHeader(CharSequence title)
Sets the header of the context menu to the title given in title.
public
void
setHeader(View headerView)
Sets the header of the context menu to the
View given in
headerView.
public
void
setHeader(CharSequence title, int iconRes)
Sets the header of the context menu to the title given in title
and the icon given in iconRes resource id.
Sets the header of the context menu to the title given in
title
and the icon given in
icon Drawable.
public
void
setItemCheckable(int id, boolean checkable)
Control whether a particular item with the given identifier can display
a check mark. This is the same as looking up the
Menu.Item and
calling
setCheckable(boolean) on it.
public
void
setItemChecked(int id, boolean checked)
Show or hide the check mark for a particular menu item selected by its
identifier. If this item is a member of a group that contains
mutually-exclusive items (set via
setGroupCheckable(int, boolean, boolean), the other items
in the group will be unchecked. This is the same as looking up the
Menu.Item and calling
setChecked(boolean) on it.
public
void
setItemShown(int id, boolean shown)
Show or hide a particular menu item selected by its identifier.
public
void
setQwertyMode(boolean isQwerty)
Control whether the menu should be running in qwerty mode (alphabetic
shortcuts) or 12-key mode (numeric shortcuts).
public
void
setShortcutsShown(boolean shortcutsShown)
Sets whether the shortcuts should be shown on menus.
Parameters
| shortcutsShown
| Whether shortcuts should be shown (if true and a
menu item does not have a shortcut defined, that item will
still NOT show a shortcut)
|
public
int
size()
Get the number of items in the menu. Note that this will change any
times items are added or removed from the menu.