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
Constructor and Description |
---|
ActionMenuItem(android.content.Context context,
int group,
int id,
int categoryOrder,
int ordering,
CharSequence title) |
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 |
invoke() |
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 actionView)
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.
|
ActionMenuItem |
setExclusiveCheckable(boolean exclusive) |
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 show)
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.
|
public ActionMenuItem(android.content.Context context, int group, int id, int categoryOrder, int ordering, CharSequence title)
public char getAlphabeticShortcut()
MenuItem
getAlphabeticShortcut
in interface MenuItem
public int getGroupId()
MenuItem
getGroupId
in interface MenuItem
public android.graphics.drawable.Drawable getIcon()
MenuItem
public android.content.Intent getIntent()
MenuItem
getIntent
in interface MenuItem
MenuItem.setIntent(android.content.Intent)
, or
null.MenuItem.setIntent(android.content.Intent)
public int getItemId()
MenuItem
public android.view.ContextMenu.ContextMenuInfo getMenuInfo()
MenuItem
getMenuInfo
in interface MenuItem
OnCreateContextMenuListener
public char getNumericShortcut()
MenuItem
getNumericShortcut
in interface 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 SubMenu getSubMenu()
MenuItem
MenuItem.hasSubMenu()
.getSubMenu
in interface MenuItem
public CharSequence getTitle()
MenuItem
public CharSequence getTitleCondensed()
MenuItem
getTitleCondensed
in interface MenuItem
public boolean hasSubMenu()
MenuItem
hasSubMenu
in interface MenuItem
public boolean isCheckable()
MenuItem
isCheckable
in interface MenuItem
MenuItem.setCheckable(boolean)
public boolean isChecked()
MenuItem
isChecked
in interface MenuItem
MenuItem.setChecked(boolean)
public boolean isEnabled()
MenuItem
public boolean isVisible()
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 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 ActionMenuItem setExclusiveCheckable(boolean exclusive)
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 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 MenuItem setIcon(android.graphics.drawable.Drawable icon)
MenuItem
Menu
for the menu types that support icons.public MenuItem setIcon(int iconRes)
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 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 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 setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener)
MenuItem
Activity#onOptionsItemSelected(MenuItem)
or
Activity#onContextItemSelected(MenuItem)
.setOnMenuItemClickListener
in interface MenuItem
menuItemClickListener
- The object to receive invokations.Activity#onOptionsItemSelected(MenuItem)
,
Activity#onContextItemSelected(MenuItem)
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 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 MenuItem setTitleCondensed(CharSequence title)
MenuItem
setTitleCondensed
in interface MenuItem
title
- The new text to be displayed as the condensed title.public MenuItem setVisible(boolean visible)
MenuItem
disabled
).setVisible
in interface MenuItem
visible
- If true then the item will be visible; if false it is
hidden.public boolean invoke()
public void setShowAsAction(int show)
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
show
- 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 actionView)
MenuItem
Note: Setting an action view overrides the action provider
set via MenuItem.setActionProvider(ActionProvider)
.
setActionView
in interface MenuItem
actionView
- View 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 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 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 boolean isActionViewExpanded()
MenuItem
isActionViewExpanded
in interface MenuItem
MenuItem.expandActionView()
,
MenuItem.collapseActionView()
,
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
,
MenuItem.OnActionExpandListener
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 eventsCopyright © 2011–2014. All rights reserved.