MenuItemCompat
class MenuItemCompat
kotlin.Any | |
↳ | androidx.core.view.MenuItemCompat |
Helper for accessing features in android.view.MenuItem
.
Note: You cannot get an instance of this class. Instead, it provides static methods that correspond to the methods in , but take a android.view.MenuItem
object as an additional argument.
Summary
Nested classes | |
---|---|
abstract |
Interface definition for a callback to be invoked when a menu item marked with |
Constants | |
---|---|
static Int |
Always show this item as a button in an Action Bar. |
static Int |
This item's action view collapses to a normal menu item. |
static Int |
Show this item as a button in an Action Bar if the system decides there is room for it. |
static Int |
Never show this item as a button in an Action Bar. |
static Int |
When this item is in the action bar, always show it with a text label even if it also has an icon specified. |
Public methods | |
---|---|
static Boolean |
collapseActionView(item: MenuItem!) Collapse the action view associated with this menu item. |
static Boolean |
expandActionView(item: MenuItem!) Expand the action view associated with this menu item. |
static ActionProvider! |
getActionProvider(item: MenuItem!) Gets the |
static View! |
getActionView(item: MenuItem!) Returns the currently set action view for this menu item. |
static Int |
getAlphabeticModifiers(item: MenuItem!) Return the modifier for this menu item's alphabetic shortcut. |
static CharSequence! |
getContentDescription(item: MenuItem!) Retrieve the content description associated with this menu item. |
static ColorStateList! |
getIconTintList(item: MenuItem!) |
static Mode! |
getIconTintMode(item: MenuItem!) Returns the blending mode used to apply the tint to the item's icon, if specified. |
static Int |
getNumericModifiers(item: MenuItem!) Return the modifiers for this menu item's numeric (12-key) shortcut. |
static CharSequence! |
getTooltipText(item: MenuItem!) Retrieve the tooltip text associated with this menu item. |
static Boolean |
isActionViewExpanded(item: MenuItem!) Returns true if this menu item's action view has been expanded. |
static MenuItem! |
setActionProvider(item: MenuItem!, provider: ActionProvider!) Sets the |
static MenuItem! |
setActionView(item: MenuItem!, view: View!) Set an action view for this menu item. |
static MenuItem! |
setActionView(item: MenuItem!, resId: Int) Set an action view for this menu item. |
static Unit |
setAlphabeticShortcut(item: MenuItem!, alphaChar: Char, alphaModifiers: Int) Change the alphabetic shortcut associated with this item. |
static Unit |
setContentDescription(item: MenuItem!, contentDescription: CharSequence!) Change the content description associated with this menu item. |
static Unit |
setIconTintList(item: MenuItem!, tint: ColorStateList!) Applies a tint to the item's icon. |
static Unit |
setIconTintMode(item: MenuItem!, tintMode: Mode!) Specifies the blending mode used to apply the tint specified by |
static Unit |
setNumericShortcut(item: MenuItem!, numericChar: Char, numericModifiers: Int) Change the numeric shortcut and modifiers associated with this item. |
static MenuItem! |
setOnActionExpandListener(item: MenuItem!, listener: MenuItemCompat.OnActionExpandListener!) Set an |
static Unit |
setShortcut(item: MenuItem!, numericChar: Char, alphaChar: Char, numericModifiers: Int, alphaModifiers: Int) Change both the numeric and alphabetic shortcut associated with this item. |
static Unit |
setShowAsAction(item: MenuItem!, actionEnum: Int) Sets how this item should display in the presence of a compatible Action Bar. |
static Unit |
setTooltipText(item: MenuItem!, tooltipText: CharSequence!) Change the tooltip text associated with this menu item. |
Constants
SHOW_AS_ACTION_ALWAYS
static valSHOW_AS_ACTION_ALWAYS: Int
Deprecated: Use MenuItem#SHOW_AS_ACTION_ALWAYS
directly.
Always show this item as a button in an Action Bar. Use sparingly! If too many items are set to always show in the Action Bar it can crowd the Action Bar and degrade the user experience on devices with smaller screens. A good rule of thumb is to have no more than 2 items set to always show at a time.
Value: 2
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
static valSHOW_AS_ACTION_COLLAPSE_ACTION_VIEW: Int
Deprecated: Use MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
directly.
This item's action view collapses to a normal menu item. When expanded, the action view temporarily takes over a larger segment of its container.
Value: 8
SHOW_AS_ACTION_IF_ROOM
static valSHOW_AS_ACTION_IF_ROOM: Int
Deprecated: Use MenuItem#SHOW_AS_ACTION_IF_ROOM
directly.
Show this item as a button in an Action Bar if the system decides there is room for it.
Value: 1
SHOW_AS_ACTION_NEVER
static valSHOW_AS_ACTION_NEVER: Int
Deprecated: Use MenuItem#SHOW_AS_ACTION_NEVER
directly.
Never show this item as a button in an Action Bar.
Value: 0
SHOW_AS_ACTION_WITH_TEXT
static valSHOW_AS_ACTION_WITH_TEXT: Int
Deprecated: Use MenuItem#SHOW_AS_ACTION_WITH_TEXT
directly.
When this item is in the action bar, always show it with a text label even if it also has an icon specified.
Value: 4
Public methods
collapseActionView
static funcollapseActionView(item: MenuItem!): Boolean
Deprecated: Use MenuItem#collapseActionView()
directly.
Collapse the action view associated with this menu item. The menu item must have an action view set, as well as the showAsAction flag SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
. If a listener has been set using setOnActionExpandListener(MenuItem, * androidx.core.view.MenuItemCompat.OnActionExpandListener)
it will have its
method invoked. The listener may return false from this method to prevent collapsing the action view.
Return | |
---|---|
Boolean |
true if the action view was collapsed, false otherwise. |
expandActionView
static funexpandActionView(item: MenuItem!): Boolean
Deprecated: Use MenuItem#expandActionView()
directly.
Expand the action view associated with this menu item. The menu item must have an action view set, as well as the showAsAction flag SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
. If a listener has been set using setOnActionExpandListener(MenuItem, OnActionExpandListener)
it will have its OnActionExpandListener#onMenuItemActionExpand(MenuItem)
method invoked. The listener may return false from this method to prevent expanding the action view.
Return | |
---|---|
Boolean |
true if the action view was expanded, false otherwise. |
getActionProvider
static fun getActionProvider(item: MenuItem!): ActionProvider!
Gets the ActionProvider
.
Return | |
---|---|
ActionProvider! |
The action provider. |
See Also