MenuItem.OnActionExpandListener, MenuItem.OnMenuItemClickListener
SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW, SHOW_AS_ACTION_IF_ROOM, SHOW_AS_ACTION_NEVER, SHOW_AS_ACTION_WITH_TEXT
Modifier and Type | Method and Description |
---|---|
void |
actionFormatChanged() |
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.
|
int |
getOrdering() |
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 |
hasCollapsibleActionView() |
boolean |
hasSubMenu()
Check whether this item has an associated sub-menu.
|
boolean |
invoke()
Invokes the item by calling various listeners or callbacks.
|
boolean |
isActionButton() |
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 |
isExclusiveCheckable() |
boolean |
isVisible()
Return the visibility of the menu item.
|
boolean |
requestsActionButton() |
boolean |
requiresActionButton() |
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.
|
void |
setActionViewExpanded(boolean isExpanded) |
MenuItem |
setAlphabeticShortcut(char alphaChar)
Change the alphabetic shortcut associated with this item.
|
MenuItem |
setCallback(Runnable callback) |
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.
|
void |
setExclusiveCheckable(boolean exclusive) |
MenuItem |
setIcon(android.graphics.drawable.Drawable icon)
Change the icon associated with this item.
|
MenuItem |
setIcon(int iconResId)
Change the icon associated with this item.
|
MenuItem |
setIntent(android.content.Intent intent)
Change the Intent associated with this item.
|
void |
setIsActionButton(boolean isActionButton) |
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 clickListener)
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 shown)
Sets the visibility of the menu item.
|
boolean |
shouldShowIcon() |
boolean |
showsTextAsAction() |
String |
toString() |
public boolean invoke()
public boolean isEnabled()
MenuItem
public MenuItem setEnabled(boolean enabled)
MenuItem
setEnabled
in interface MenuItem
enabled
- If true then the item will be invokable; if false it is
won't be invokable.public int getGroupId()
MenuItem
getGroupId
in interface MenuItem
public int getItemId()
MenuItem
public int getOrder()
MenuItem
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.
public int getOrdering()
public android.content.Intent getIntent()
MenuItem
getIntent
in interface MenuItem
MenuItem.setIntent(android.content.Intent)
, or
null.MenuItem.setIntent(android.content.Intent)
public MenuItem setIntent(android.content.Intent intent)
MenuItem
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.
setIntent
in interface MenuItem
intent
- The Intent to associated with the item. This Intent
object is not copied, so be careful not to
modify it later.MenuItem.getIntent()
public char getAlphabeticShortcut()
MenuItem
getAlphabeticShortcut
in interface MenuItem
public MenuItem setAlphabeticShortcut(char alphaChar)
MenuItem
See Menu
for the menu types that support shortcuts.
setAlphabeticShortcut
in interface MenuItem
alphaChar
- The alphabetic shortcut key. This is the shortcut when
using a keyboard with alphabetic keys.public char getNumericShortcut()
MenuItem
getNumericShortcut
in interface MenuItem
public MenuItem setNumericShortcut(char numericChar)
MenuItem
See Menu
for the menu types that support shortcuts.
setNumericShortcut
in interface MenuItem
numericChar
- The numeric shortcut key. This is the shortcut when
using a 12-key (numeric) keyboard.public MenuItem setShortcut(char numericChar, char alphaChar)
MenuItem
See Menu
for the menu types that support shortcuts.
setShortcut
in interface MenuItem
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.public SubMenu getSubMenu()
MenuItem
MenuItem.hasSubMenu()
.getSubMenu
in interface MenuItem
public boolean hasSubMenu()
MenuItem
hasSubMenu
in interface MenuItem
public CharSequence getTitle()
MenuItem
public MenuItem setTitle(CharSequence title)
MenuItem
public MenuItem setTitle(int title)
MenuItem
Some menu types do not sufficient space to show the full title, and
instead a condensed title is preferred. See Menu
for more
information.
setTitle
in interface MenuItem
title
- The resource id of the new text to be displayed.MenuItem.setTitleCondensed(CharSequence)
public CharSequence getTitleCondensed()
MenuItem
getTitleCondensed
in interface MenuItem
public MenuItem setTitleCondensed(CharSequence title)
MenuItem
setTitleCondensed
in interface MenuItem
title
- The new text to be displayed as the condensed title.public android.graphics.drawable.Drawable getIcon()
MenuItem
public MenuItem setIcon(android.graphics.drawable.Drawable icon)
MenuItem
Menu
for the menu types that support icons.public MenuItem setIcon(int iconResId)
MenuItem
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 boolean isCheckable()
MenuItem
isCheckable
in interface MenuItem
MenuItem.setCheckable(boolean)
public MenuItem setCheckable(boolean checkable)
MenuItem
MenuItem.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.
setCheckable
in interface MenuItem
checkable
- Set to true to allow a check mark, false to
disallow. The default is false.MenuItem.setChecked(boolean)
,
MenuItem.isCheckable()
,
Menu.setGroupCheckable(int, boolean, boolean)
public void setExclusiveCheckable(boolean exclusive)
public boolean isExclusiveCheckable()
public boolean isChecked()
MenuItem
isChecked
in interface MenuItem
MenuItem.setChecked(boolean)
public MenuItem setChecked(boolean checked)
MenuItem
MenuItem.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.
setChecked
in interface MenuItem
checked
- Set to true to display a check mark, false to hide
it. The default value is false.MenuItem.setCheckable(boolean)
,
MenuItem.isChecked()
,
Menu.setGroupCheckable(int, boolean, boolean)
public boolean isVisible()
MenuItem
public MenuItem setVisible(boolean shown)
MenuItem
disabled
).setVisible
in interface MenuItem
shown
- If true then the item will be visible; if false it is
hidden.public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener clickListener)
MenuItem
Activity#onOptionsItemSelected(MenuItem)
or
Activity#onContextItemSelected(MenuItem)
.setOnMenuItemClickListener
in interface MenuItem
clickListener
- The object to receive invokations.Activity#onOptionsItemSelected(MenuItem)
,
Activity#onContextItemSelected(MenuItem)
public android.view.ContextMenu.ContextMenuInfo getMenuInfo()
MenuItem
getMenuInfo
in interface MenuItem
OnCreateContextMenuListener
public void actionFormatChanged()
public boolean shouldShowIcon()
public boolean isActionButton()
public boolean requestsActionButton()
public boolean requiresActionButton()
public void setIsActionButton(boolean isActionButton)
public boolean showsTextAsAction()
public void setShowAsAction(int actionEnum)
MenuItem
MenuItem.SHOW_AS_ACTION_ALWAYS
,
MenuItem.SHOW_AS_ACTION_IF_ROOM
, or MenuItem.SHOW_AS_ACTION_NEVER
should
be used, and you may optionally OR the value with MenuItem.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.setShowAsAction
in interface MenuItem
actionEnum
- How the item should display. One of
MenuItem.SHOW_AS_ACTION_ALWAYS
, MenuItem.SHOW_AS_ACTION_IF_ROOM
, or
MenuItem.SHOW_AS_ACTION_NEVER
. SHOW_AS_ACTION_NEVER is the default.ActionBar
,
MenuItem.setActionView(View)
public MenuItem setActionView(android.view.View view)
MenuItem
Note: Setting an action view overrides the action provider
set via MenuItem.setActionProvider(ActionProvider)
.
setActionView
in interface MenuItem
view
- View to use for presenting this item to the user.MenuItem.setShowAsAction(int)
public MenuItem setActionView(int resId)
MenuItem
Note: Setting an action view overrides the action provider
set via MenuItem.setActionProvider(ActionProvider)
.
setActionView
in interface MenuItem
resId
- Layout resource to use for presenting this item to the user.MenuItem.setShowAsAction(int)
public android.view.View getActionView()
MenuItem
getActionView
in interface MenuItem
MenuItem.setActionView(View)
,
MenuItem.setShowAsAction(int)
public ActionProvider getActionProvider()
MenuItem
ActionProvider
.getActionProvider
in interface MenuItem
ActionProvider
,
MenuItem.setActionProvider(ActionProvider)
public MenuItem setActionProvider(ActionProvider actionProvider)
MenuItem
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 MenuItem.setActionView(int)
or MenuItem.setActionView(View)
.
setActionProvider
in interface MenuItem
actionProvider
- The action provider.ActionProvider
public MenuItem setShowAsActionFlags(int actionEnum)
MenuItem
MenuItem.SHOW_AS_ACTION_ALWAYS
,
MenuItem.SHOW_AS_ACTION_IF_ROOM
, or MenuItem.SHOW_AS_ACTION_NEVER
should
be used, and you may optionally OR the value with MenuItem.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 MenuItem.setShowAsAction(int)
only in that it
returns the current MenuItem instance for call chaining.
setShowAsActionFlags
in interface MenuItem
actionEnum
- How the item should display. One of
MenuItem.SHOW_AS_ACTION_ALWAYS
, MenuItem.SHOW_AS_ACTION_IF_ROOM
, or
MenuItem.SHOW_AS_ACTION_NEVER
. SHOW_AS_ACTION_NEVER is the default.ActionBar
,
MenuItem.setActionView(View)
public boolean expandActionView()
MenuItem
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
.
If a listener has been set using MenuItem.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.expandActionView
in interface MenuItem
public boolean collapseActionView()
MenuItem
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
. If a listener has been set using
MenuItem.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.collapseActionView
in interface MenuItem
public MenuItem setOnActionExpandListener(MenuItem.OnActionExpandListener listener)
MenuItem
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
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
.setOnActionExpandListener
in interface MenuItem
listener
- Listener that will respond to expand/collapse eventspublic boolean hasCollapsibleActionView()
public void setActionViewExpanded(boolean isExpanded)
public boolean isActionViewExpanded()
MenuItem
isActionViewExpanded
in interface MenuItem
MenuItem.expandActionView()
,
MenuItem.collapseActionView()
,
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
,
MenuItem.OnActionExpandListener
Copyright © 2011–2014. All rights reserved.