Methods Summary |
---|
public boolean | collapseActionView()Collapse the action view associated with this menu item.
The menu item must have an action view set, as well as the showAsAction flag
{@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}. If a listener has been set using
{@link #setOnActionExpandListener(OnActionExpandListener)} it will have its
{@link OnActionExpandListener#onMenuItemActionCollapse(MenuItem)} method invoked.
The listener may return false from this method to prevent collapsing the action view.
|
public boolean | expandActionView()Expand the action view associated with this menu item.
The menu item must have an action view set, as well as
the showAsAction flag {@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}.
If a listener has been set using {@link #setOnActionExpandListener(OnActionExpandListener)}
it will have its {@link OnActionExpandListener#onMenuItemActionExpand(MenuItem)}
method invoked. The listener may return false from this method to prevent expanding
the action view.
|
public ActionProvider | getActionProvider()Gets the {@link ActionProvider}.
|
public View | getActionView()Returns the currently set action view for this menu item.
|
public char | getAlphabeticShortcut()Return the char for this menu item's alphabetic shortcut.
|
public int | getGroupId()Return the group identifier that this menu item is part of. The group
identifier can not be changed after the menu is created.
|
public 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).
|
public android.content.Intent | getIntent()Return the Intent associated with this item. This returns a
reference to the Intent which you can change as desired to modify
what the Item is holding.
|
public int | getItemId()Return the identifier for this menu item. The identifier can not
be changed after the menu is created.
|
public android.view.ContextMenu.ContextMenuInfo | getMenuInfo()Gets the extra information linked to this menu item. This extra
information is set by the View that added this menu item to the
menu.
|
public char | getNumericShortcut()Return the char for this menu item's numeric (12-key) shortcut.
|
public int | getOrder()Return the category and order within the category of this item. This
item will be shown before all items (within its category) that have
order greater than this value.
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 {@link Menu#CATEGORY_SYSTEM},
{@link Menu#CATEGORY_SECONDARY}, {@link Menu#CATEGORY_ALTERNATIVE},
{@link Menu#CATEGORY_CONTAINER}. See {@link Menu} for a full list.
|
public SubMenu | getSubMenu()Get the sub-menu to be invoked when this item is selected, if it has
one. See {@link #hasSubMenu()}.
|
public java.lang.CharSequence | getTitle()Retrieve the current title of the item.
|
public java.lang.CharSequence | getTitleCondensed()Retrieve the current condensed title of the item. If a condensed
title was never set, it will return the normal title.
|
public boolean | hasSubMenu()Check whether this item has an associated sub-menu. I.e. it is a
sub-menu of another menu.
|
public boolean | isActionViewExpanded()Returns true if this menu item's action view has been expanded.
|
public boolean | isCheckable()Return whether the item can currently display a check mark.
|
public boolean | isChecked()Return whether the item is currently displaying a check mark.
|
public boolean | isEnabled()Return the enabled state of the menu item.
|
public boolean | isVisible()Return the visibility of the menu item.
|
public android.view.MenuItem | setActionProvider(ActionProvider actionProvider)Sets the {@link 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 {@link #setActionView(int)} or {@link #setActionView(View)}.
|
public android.view.MenuItem | setActionView(View view)Set an action view for this menu item. An action view will be displayed in place
of an automatically generated menu item element in the UI when this item is shown
as an action within a parent.
Note: Setting an action view overrides the action provider
set via {@link #setActionProvider(ActionProvider)}.
|
public android.view.MenuItem | setActionView(int resId)Set an action view for this menu item. An action view will be displayed in place
of an automatically generated menu item element in the UI when this item is shown
as an action within a parent.
Note: Setting an action view overrides the action provider
set via {@link #setActionProvider(ActionProvider)}.
|
public android.view.MenuItem | setAlphabeticShortcut(char alphaChar)Change the alphabetic shortcut associated with this item. The shortcut
will be triggered when the key that generates the given character is
pressed along with the ctrl key. Case is not significant and shortcut
characters will be displayed in lower case. Note that menu items with
the characters '\b' or '\n' as shortcuts will get triggered by the
Delete key or Carriage Return key, respectively.
See {@link Menu} for the menu types that support shortcuts.
|
public android.view.MenuItem | setCheckable(boolean checkable)Control whether this item can display a check mark. Setting this does
not actually display a check mark (see {@link #setChecked} for that);
rather, it ensures there is room in the item in which to display a
check mark.
See {@link Menu} for the menu types that support check marks.
|
public android.view.MenuItem | setChecked(boolean checked)Control whether this item is shown with a check mark. Note that you
must first have enabled checking with {@link #setCheckable} or else
the check mark will not appear. If this item is a member of a group that contains
mutually-exclusive items (set via {@link Menu#setGroupCheckable(int, boolean, boolean)},
the other items in the group will be unchecked.
See {@link Menu} for the menu types that support check marks.
|
public android.view.MenuItem | setEnabled(boolean enabled)Sets whether the menu item is enabled. Disabling a menu item will not
allow it to be invoked via its shortcut. The menu item will still be
visible.
|
public android.view.MenuItem | setIcon(int iconRes)Change the icon associated with this item. This icon will not always be
shown, so the title should be sufficient in describing this item. See
{@link 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.
|
public android.view.MenuItem | setIcon(android.graphics.drawable.Drawable icon)Change the icon associated with this item. This icon will not always be
shown, so the title should be sufficient in describing this item. See
{@link Menu} for the menu types that support icons.
|
public android.view.MenuItem | setIntent(android.content.Intent intent)Change the Intent associated with this item. By default there is no
Intent associated with a menu item. If you set one, and nothing
else handles the item, then the default behavior will be to call
{@link android.content.Context#startActivity} with the given Intent.
Note that setIntent() can not be used with the versions of
{@link Menu#add} that take a Runnable, because {@link 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.
|
public android.view.MenuItem | setNumericShortcut(char numericChar)Change the numeric shortcut associated with this item.
See {@link Menu} for the menu types that support shortcuts.
|
public android.view.MenuItem | setOnActionExpandListener(android.view.MenuItem$OnActionExpandListener listener)Set an {@link 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
{@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}.
|
public android.view.MenuItem | setOnMenuItemClickListener(android.view.MenuItem$OnMenuItemClickListener menuItemClickListener)Set a custom listener for invocation of this menu item. In most
situations, it is more efficient and easier to use
{@link Activity#onOptionsItemSelected(MenuItem)} or
{@link Activity#onContextItemSelected(MenuItem)}.
|
public android.view.MenuItem | setShortcut(char numericChar, char alphaChar)Change both the numeric and alphabetic shortcut associated with this
item. Note that the shortcut will be triggered when the key that
generates the given character is pressed along with the ctrl key.
Also note that case is not significant and that alphabetic shortcut
characters will be displayed in lower case.
See {@link Menu} for the menu types that support shortcuts.
|
public void | setShowAsAction(int actionEnum)Sets how this item should display in the presence of an Action Bar.
The parameter actionEnum is a flag set. One of {@link #SHOW_AS_ACTION_ALWAYS},
{@link #SHOW_AS_ACTION_IF_ROOM}, or {@link #SHOW_AS_ACTION_NEVER} should
be used, and you may optionally OR the value with {@link #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.
|
public android.view.MenuItem | setShowAsActionFlags(int actionEnum)Sets how this item should display in the presence of an Action Bar.
The parameter actionEnum is a flag set. One of {@link #SHOW_AS_ACTION_ALWAYS},
{@link #SHOW_AS_ACTION_IF_ROOM}, or {@link #SHOW_AS_ACTION_NEVER} should
be used, and you may optionally OR the value with {@link #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 {@link #setShowAsAction(int)} only in that it
returns the current MenuItem instance for call chaining.
|
public android.view.MenuItem | setTitle(java.lang.CharSequence title)Change the title associated with this item.
|
public android.view.MenuItem | setTitle(int title)Change the title associated with this item.
Some menu types do not sufficient space to show the full title, and
instead a condensed title is preferred. See {@link Menu} for more
information.
|
public android.view.MenuItem | setTitleCondensed(java.lang.CharSequence title)Change the condensed title associated with this item. The condensed
title is used in situations where the normal title may be too long to
be displayed.
|
public android.view.MenuItem | setVisible(boolean visible)Sets the visibility of the menu item. Even if a menu item is not visible,
it may still be invoked via its shortcut (to completely disable an item,
set it to invisible and {@link #setEnabled(boolean) disabled}).
|