public interface MenuItem
| Modifier and Type | Interface and Description | 
|---|---|
static interface  | 
MenuItem.OnActionExpandListener
Interface definition for a callback to be invoked when a menu item
 marked with  
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW is
 expanded or collapsed. | 
static interface  | 
MenuItem.OnMenuItemClickListener
Interface definition for a callback to be invoked when a menu item is
 clicked. 
 | 
| Modifier and Type | Field and Description | 
|---|---|
static int | 
SHOW_AS_ACTION_ALWAYS
Always show this item as a button in an Action Bar. 
 | 
static int | 
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
This item's action view collapses to a normal menu item. 
 | 
static int | 
SHOW_AS_ACTION_IF_ROOM
Show this item as a button in an Action Bar if the system decides there is room for it. 
 | 
static int | 
SHOW_AS_ACTION_NEVER
Never show this item as a button in an Action Bar. 
 | 
static int | 
SHOW_AS_ACTION_WITH_TEXT
When this item is in the action bar, always show it with a text label even if
 it also has an icon specified. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
boolean | 
collapseActionView()
Collapse the action view associated with this menu item. 
 | 
boolean | 
expandActionView()
Expand the action view associated with this menu item. 
 | 
ActionProvider | 
getActionProvider()
Gets the  
ActionProvider. | 
android.view.View | 
getActionView()
Returns the currently set action view for this menu item. 
 | 
char | 
getAlphabeticShortcut()
Return the char for this menu item's alphabetic shortcut. 
 | 
int | 
getGroupId()
Return the group identifier that this menu item is part of. 
 | 
android.graphics.drawable.Drawable | 
getIcon()
Returns the icon for this item as a Drawable (getting it from resources if it hasn't been
 loaded before). 
 | 
android.content.Intent | 
getIntent()
Return the Intent associated with this item. 
 | 
int | 
getItemId()
Return the identifier for this menu item. 
 | 
android.view.ContextMenu.ContextMenuInfo | 
getMenuInfo()
Gets the extra information linked to this menu item. 
 | 
char | 
getNumericShortcut()
Return the char for this menu item's numeric (12-key) shortcut. 
 | 
int | 
getOrder()
Return the category and order within the category of this item. 
 | 
SubMenu | 
getSubMenu()
Get the sub-menu to be invoked when this item is selected, if it has
 one. 
 | 
CharSequence | 
getTitle()
Retrieve the current title of the item. 
 | 
CharSequence | 
getTitleCondensed()
Retrieve the current condensed title of the item. 
 | 
boolean | 
hasSubMenu()
Check whether this item has an associated sub-menu. 
 | 
boolean | 
isActionViewExpanded()
Returns true if this menu item's action view has been expanded. 
 | 
boolean | 
isCheckable()
Return whether the item can currently display a check mark. 
 | 
boolean | 
isChecked()
Return whether the item is currently displaying a check mark. 
 | 
boolean | 
isEnabled()
Return the enabled state of the menu item. 
 | 
boolean | 
isVisible()
Return the visibility of the menu item. 
 | 
MenuItem | 
setActionProvider(ActionProvider actionProvider)
Sets the  
ActionProvider responsible for creating an action view if
 the item is placed on the action bar. | 
MenuItem | 
setActionView(int resId)
Set an action view for this menu item. 
 | 
MenuItem | 
setActionView(android.view.View view)
Set an action view for this menu item. 
 | 
MenuItem | 
setAlphabeticShortcut(char alphaChar)
Change the alphabetic shortcut associated with this item. 
 | 
MenuItem | 
setCheckable(boolean checkable)
Control whether this item can display a check mark. 
 | 
MenuItem | 
setChecked(boolean checked)
Control whether this item is shown with a check mark. 
 | 
MenuItem | 
setEnabled(boolean enabled)
Sets whether the menu item is enabled. 
 | 
MenuItem | 
setIcon(android.graphics.drawable.Drawable icon)
Change the icon associated with this item. 
 | 
MenuItem | 
setIcon(int iconRes)
Change the icon associated with this item. 
 | 
MenuItem | 
setIntent(android.content.Intent intent)
Change the Intent associated with this item. 
 | 
MenuItem | 
setNumericShortcut(char numericChar)
Change the numeric shortcut associated with this item. 
 | 
MenuItem | 
setOnActionExpandListener(MenuItem.OnActionExpandListener listener)
Set an  
MenuItem.OnActionExpandListener on this menu item to be notified when
 the associated action view is expanded or collapsed. | 
MenuItem | 
setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener)
Set a custom listener for invocation of this menu item. 
 | 
MenuItem | 
setShortcut(char numericChar,
           char alphaChar)
Change both the numeric and alphabetic shortcut associated with this
 item. 
 | 
void | 
setShowAsAction(int actionEnum)
Sets how this item should display in the presence of an Action Bar. 
 | 
MenuItem | 
setShowAsActionFlags(int actionEnum)
Sets how this item should display in the presence of an Action Bar. 
 | 
MenuItem | 
setTitle(CharSequence title)
Change the title associated with this item. 
 | 
MenuItem | 
setTitle(int title)
Change the title associated with this item. 
 | 
MenuItem | 
setTitleCondensed(CharSequence title)
Change the condensed title associated with this item. 
 | 
MenuItem | 
setVisible(boolean visible)
Sets the visibility of the menu item. 
 | 
static final int SHOW_AS_ACTION_NEVER
static final int SHOW_AS_ACTION_IF_ROOM
static final int SHOW_AS_ACTION_ALWAYS
static final int SHOW_AS_ACTION_WITH_TEXT
static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
int getItemId()
int getGroupId()
int getOrder()
 An order integer contains the item's category (the upper bits of the
 integer; set by or/add the category with the order within the
 category) and the ordering of the item within that category (the
 lower bits). Example categories are Menu.CATEGORY_SYSTEM,
 Menu.CATEGORY_SECONDARY, Menu.CATEGORY_ALTERNATIVE,
 Menu.CATEGORY_CONTAINER. See Menu for a full list.
MenuItem setTitle(CharSequence title)
title - The new text to be displayed.MenuItem setTitle(int title)
 Some menu types do not sufficient space to show the full title, and
 instead a condensed title is preferred. See Menu for more
 information.
title - The resource id of the new text to be displayed.setTitleCondensed(CharSequence)CharSequence getTitle()
MenuItem setTitleCondensed(CharSequence title)
title - The new text to be displayed as the condensed title.CharSequence getTitleCondensed()
MenuItem setIcon(android.graphics.drawable.Drawable icon)
Menu for the menu types that support icons.icon - The new icon (as a Drawable) to be displayed.MenuItem setIcon(int iconRes)
Menu for the menu types that support icons.
 This method will set the resource ID of the icon which will be used to lazily get the Drawable when this item is being shown.
iconRes - The new icon (as a resource ID) to be displayed.android.graphics.drawable.Drawable getIcon()
MenuItem setIntent(android.content.Intent intent)
Context.startActivity(android.content.Intent) with the given Intent.
 Note that setIntent() can not be used with the versions of
 Menu.add(java.lang.CharSequence) that take a Runnable, because Runnable.run()
 does not return a value so there is no way to tell if it handled the
 item.  In this case it is assumed that the Runnable always handles
 the item, and the intent will never be started.
intent - The Intent to associated with the item.  This Intent
               object is not copied, so be careful not to
               modify it later.getIntent()android.content.Intent getIntent()
setIntent(android.content.Intent), or
         null.setIntent(android.content.Intent)MenuItem setShortcut(char numericChar, char alphaChar)
 See Menu for the menu types that support shortcuts.
numericChar - The numeric shortcut key. This is the shortcut when
        using a numeric (e.g., 12-key) keyboard.alphaChar - The alphabetic shortcut key. This is the shortcut when
        using a keyboard with alphabetic keys.MenuItem setNumericShortcut(char numericChar)
 See Menu for the menu types that support shortcuts.
numericChar - The numeric shortcut key.  This is the shortcut when
                 using a 12-key (numeric) keyboard.char getNumericShortcut()
MenuItem setAlphabeticShortcut(char alphaChar)
 See Menu for the menu types that support shortcuts.
alphaChar - The alphabetic shortcut key. This is the shortcut when
        using a keyboard with alphabetic keys.char getAlphabeticShortcut()
MenuItem setCheckable(boolean checkable)
setChecked(boolean) for that);
 rather, it ensures there is room in the item in which to display a
 check mark.
 
 See Menu for the menu types that support check marks.
checkable - Set to true to allow a check mark, false to
            disallow. The default is false.setChecked(boolean), 
isCheckable(), 
Menu.setGroupCheckable(int, boolean, boolean)boolean isCheckable()
setCheckable(boolean)MenuItem setChecked(boolean checked)
setCheckable(boolean) or else
 the check mark will not appear.  If this item is a member of a group that contains
 mutually-exclusive items (set via Menu.setGroupCheckable(int, boolean, boolean),
 the other items in the group will be unchecked.
 
 See Menu for the menu types that support check marks.
checked - Set to true to display a check mark, false to hide
                it.  The default value is false.setCheckable(boolean), 
isChecked(), 
Menu.setGroupCheckable(int, boolean, boolean)boolean isChecked()
setChecked(boolean)MenuItem setVisible(boolean visible)
disabled).visible - If true then the item will be visible; if false it is
        hidden.boolean isVisible()
MenuItem setEnabled(boolean enabled)
enabled - If true then the item will be invokable; if false it is
        won't be invokable.boolean isEnabled()
boolean hasSubMenu()
SubMenu getSubMenu()
hasSubMenu().MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener)
Activity#onOptionsItemSelected(MenuItem) or
 Activity#onContextItemSelected(MenuItem).menuItemClickListener - The object to receive invokations.Activity#onOptionsItemSelected(MenuItem), 
Activity#onContextItemSelected(MenuItem)android.view.ContextMenu.ContextMenuInfo getMenuInfo()
OnCreateContextMenuListenervoid setShowAsAction(int actionEnum)
SHOW_AS_ACTION_ALWAYS,
 SHOW_AS_ACTION_IF_ROOM, or SHOW_AS_ACTION_NEVER should
 be used, and you may optionally OR the value with SHOW_AS_ACTION_WITH_TEXT.
 SHOW_AS_ACTION_WITH_TEXT requests that when the item is shown as an action,
 it should be shown with a text label.actionEnum - How the item should display. One of
 SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_IF_ROOM, or
 SHOW_AS_ACTION_NEVER. SHOW_AS_ACTION_NEVER is the default.ActionBar, 
setActionView(View)MenuItem setShowAsActionFlags(int actionEnum)
SHOW_AS_ACTION_ALWAYS,
 SHOW_AS_ACTION_IF_ROOM, or SHOW_AS_ACTION_NEVER should
 be used, and you may optionally OR the value with SHOW_AS_ACTION_WITH_TEXT.
 SHOW_AS_ACTION_WITH_TEXT requests that when the item is shown as an action,
 it should be shown with a text label.
 Note: This method differs from setShowAsAction(int) only in that it
 returns the current MenuItem instance for call chaining.
actionEnum - How the item should display. One of
 SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_IF_ROOM, or
 SHOW_AS_ACTION_NEVER. SHOW_AS_ACTION_NEVER is the default.ActionBar, 
setActionView(View)MenuItem setActionView(android.view.View view)
   Note: Setting an action view overrides the action provider
           set via setActionProvider(ActionProvider).
 
view - View to use for presenting this item to the user.setShowAsAction(int)MenuItem setActionView(int resId)
   Note: Setting an action view overrides the action provider
           set via setActionProvider(ActionProvider).
 
resId - Layout resource to use for presenting this item to the user.setShowAsAction(int)android.view.View getActionView()
setActionView(View), 
setShowAsAction(int)MenuItem setActionProvider(ActionProvider actionProvider)
ActionProvider responsible for creating an action view if
 the item is placed on the action bar. The provider also provides a default
 action invoked if the item is placed in the overflow menu.
 
   Note: Setting an action provider overrides the action view
           set via setActionView(int) or setActionView(View).
 
actionProvider - The action provider.ActionProviderActionProvider getActionProvider()
ActionProvider.ActionProvider, 
setActionProvider(ActionProvider)boolean expandActionView()
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.
 If a listener has been set using setOnActionExpandListener(OnActionExpandListener)
 it will have its MenuItem.OnActionExpandListener.onMenuItemActionExpand(MenuItem)
 method invoked. The listener may return false from this method to prevent expanding
 the action view.boolean collapseActionView()
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW. If a listener has been set using
 setOnActionExpandListener(OnActionExpandListener) it will have its
 MenuItem.OnActionExpandListener.onMenuItemActionCollapse(MenuItem) method invoked.
 The listener may return false from this method to prevent collapsing the action view.boolean isActionViewExpanded()
expandActionView(), 
collapseActionView(), 
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW, 
MenuItem.OnActionExpandListenerMenuItem setOnActionExpandListener(MenuItem.OnActionExpandListener listener)
MenuItem.OnActionExpandListener on this menu item to be notified when
 the associated action view is expanded or collapsed. The menu item must
 be configured to expand or collapse its action view using the flag
 SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.listener - Listener that will respond to expand/collapse eventsCopyright © 2011–2014. All rights reserved.