public final class MenuItemCompat extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
MenuItemCompat.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. |
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 |
---|---|
static boolean |
collapseActionView(MenuItem item)
Collapse the action view associated with this menu item.
|
static boolean |
expandActionView(MenuItem item)
Expand the action view associated with this menu item.
|
static ActionProvider |
getActionProvider(MenuItem item)
Gets the
ActionProvider . |
static View |
getActionView(MenuItem item)
Returns the currently set action view for this menu item.
|
static boolean |
isActionViewExpanded(MenuItem item)
Returns true if this menu item's action view has been expanded.
|
static MenuItem |
setActionProvider(MenuItem item,
ActionProvider provider)
Sets the
ActionProvider responsible for creating an action view if
the item is placed on the action bar. |
static MenuItem |
setActionView(MenuItem item,
int resId)
Set an action view for this menu item.
|
static MenuItem |
setActionView(MenuItem item,
View view)
Set an action view for this menu item.
|
static MenuItem |
setOnActionExpandListener(MenuItem item,
MenuItemCompat.OnActionExpandListener listener)
Set an
MenuItemCompat.OnActionExpandListener on this menu
item to be notified when the associated action view is expanded or collapsed. |
static void |
setShowAsAction(MenuItem item,
int actionEnum)
Sets how this item should display in the presence of a compatible Action Bar.
|
public static final int SHOW_AS_ACTION_NEVER
public static final int SHOW_AS_ACTION_IF_ROOM
public static final int SHOW_AS_ACTION_ALWAYS
public static final int SHOW_AS_ACTION_WITH_TEXT
public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
public static void setShowAsAction(MenuItem item, int actionEnum)
MenuItem.setShowAsAction(int)
.item
- - the item to changeactionEnum
- - How the item should display.public static MenuItem setActionView(MenuItem item, View view)
item
- the item to changeview
- View to use for presenting this item to the user.setShowAsAction(MenuItem, int)
public static MenuItem setActionView(MenuItem item, int resId)
Note: Setting an action view overrides the action provider
set via setActionProvider(MenuItem, ActionProvider)
.
item
- the item to changeresId
- Layout resource to use for presenting this item to the user.setShowAsAction(MenuItem, int)
public static View getActionView(MenuItem item)
item
- the item to querypublic static MenuItem setActionProvider(MenuItem item, ActionProvider provider)
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(MenuItem, View)
.
item
- item to changeprovider
- The action provider.ActionProvider
public static ActionProvider getActionProvider(MenuItem item)
ActionProvider
.ActionProvider
,
setActionProvider(MenuItem, ActionProvider)
public static boolean expandActionView(MenuItem item)
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
.
If a listener has been set using
setOnActionExpandListener(MenuItem, OnActionExpandListener)
it will have its MenuItemCompat.OnActionExpandListener.onMenuItemActionExpand(MenuItem)
method invoked. The listener may return false from this method to prevent expanding
the action view.public static boolean collapseActionView(MenuItem item)
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
. If a
listener has been set using setOnActionExpandListener(MenuItem,
android.support.v4.view.MenuItemCompat.OnActionExpandListener)
it will have its MenuItemCompat.OnActionExpandListener.onMenuItemActionCollapse(MenuItem)
method invoked. The listener may return false from this method to prevent collapsing
the action view.public static boolean isActionViewExpanded(MenuItem item)
expandActionView(MenuItem)
,
collapseActionView(MenuItem)
,
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
,
MenuItemCompat.OnActionExpandListener
public static MenuItem setOnActionExpandListener(MenuItem item, MenuItemCompat.OnActionExpandListener listener)
MenuItemCompat.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 events