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. |
getActionView
static fungetActionView(item: MenuItem!): View!
Deprecated: Use MenuItem#getActionView()
directly.
Returns the currently set action view for this menu item.
Parameters | |
---|---|
item |
MenuItem!: the item to query |
Return | |
---|---|
View!: This item's action view |
getAlphabeticModifiers
static fun getAlphabeticModifiers(item: MenuItem!): Int
Return the modifier for this menu item's alphabetic shortcut. The modifier is a combination of KeyEvent#META_META_ON
, KeyEvent#META_CTRL_ON
, KeyEvent#META_ALT_ON
, KeyEvent#META_SHIFT_ON
, KeyEvent#META_SYM_ON
, KeyEvent#META_FUNCTION_ON
. For example, KeyEvent#META_FUNCTION_ON
|KeyEvent#META_CTRL_ON
Return | |
---|---|
Int: Modifier associated with the keyboard shortcut. |
getContentDescription
static fun getContentDescription(item: MenuItem!): CharSequence!
Retrieve the content description associated with this menu item.
Return | |
---|---|
CharSequence!: The content description. |
getIconTintList
static fun getIconTintList(item: MenuItem!): ColorStateList!
Return | |
---|---|
ColorStateList!: the tint applied to the item's icon |
getIconTintMode
static fun getIconTintMode(item: MenuItem!): Mode!
Returns the blending mode used to apply the tint to the item's icon, if specified.
Return | |
---|---|
Mode!: the blending mode used to apply the tint to the item's icon |
getNumericModifiers
static fun getNumericModifiers(item: MenuItem!): Int
Return the modifiers for this menu item's numeric (12-key) shortcut. The modifier is a combination of KeyEvent#META_META_ON
, KeyEvent#META_CTRL_ON
, KeyEvent#META_ALT_ON
, KeyEvent#META_SHIFT_ON
, KeyEvent#META_SYM_ON
, KeyEvent#META_FUNCTION_ON
. For example, KeyEvent#META_FUNCTION_ON
|KeyEvent#META_CTRL_ON
Return | |
---|---|
Int: Modifier associated with the numeric shortcut. |
getTooltipText
static fun getTooltipText(item: MenuItem!): CharSequence!
Retrieve the tooltip text associated with this menu item.
Return | |
---|---|
CharSequence!: The tooltip text. |
isActionViewExpanded
static funisActionViewExpanded(item: MenuItem!): Boolean
Deprecated: Use MenuItem#isActionViewExpanded()
directly.
Returns true if this menu item's action view has been expanded.
Return | |
---|---|
Boolean: true if the item's action view is expanded, false otherwise. |
setActionProvider
static fun setActionProvider(item: MenuItem!, provider: ActionProvider!): MenuItem!
Sets the 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)
.
Parameters | |
---|---|
item |
MenuItem!: item to change |
provider |
MenuItem!: The action provider. |
Return | |
---|---|
MenuItem!: This Item so additional setters can be called. |
See Also
setActionView
static funsetActionView(item: MenuItem!, view: View!): MenuItem!
Deprecated: Use MenuItem#setActionView(View)
directly.
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.
Parameters | |
---|---|
item |
MenuItem!: the item to change |
view |
MenuItem!: View to use for presenting this item to the user. |
Return | |
---|---|
MenuItem!: This Item so additional setters can be called. |
See Also
setActionView
static funsetActionView(item: MenuItem!, resId: Int): MenuItem!
Deprecated: Use MenuItem#setActionView(int)
directly.
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 setActionProvider(MenuItem, ActionProvider)
.
Parameters | |
---|---|
item |
MenuItem!: the item to change |
resId |
MenuItem!: Layout resource to use for presenting this item to the user. |
Return | |
---|---|
MenuItem!: This Item so additional setters can be called. |
See Also
setAlphabeticShortcut
static fun setAlphabeticShortcut(item: MenuItem!, alphaChar: Char, alphaModifiers: Int): Unit
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 modifier keys. 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 Menu
for the menu types that support shortcuts.
Parameters | |
---|---|
alphaChar |
MenuItem!: The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys. |
alphaModifiers |
MenuItem!: The modifier associated with the shortcut. It should be a combination of KeyEvent#META_META_ON , KeyEvent#META_CTRL_ON , KeyEvent#META_ALT_ON , KeyEvent#META_SHIFT_ON , KeyEvent#META_SYM_ON , KeyEvent#META_FUNCTION_ON . |
setContentDescription
static fun setContentDescription(item: MenuItem!, contentDescription: CharSequence!): Unit
Change the content description associated with this menu item.
Parameters | |
---|---|
item |
MenuItem!: item to change. |
contentDescription |
MenuItem!: The new content description. |
setIconTintList
static fun setIconTintList(item: MenuItem!, tint: ColorStateList!): Unit
Applies a tint to the item's icon. Does not modify the current tint mode of that item, which is PorterDuff.Mode#SRC_IN
by default.
Subsequent calls to MenuItem#setIcon(Drawable)
or MenuItem#setIcon(int)
will automatically mutate the icon and apply the specified tint and tint mode.
Parameters | |
---|---|
tint |
MenuItem!: the tint to apply, may be null to clear tint |
See Also
setIconTintMode
static fun setIconTintMode(item: MenuItem!, tintMode: Mode!): Unit
Specifies the blending mode used to apply the tint specified by setIconTintList(MenuItem, ColorStateList)
to the item's icon. The default mode is PorterDuff.Mode#SRC_IN
.
Parameters | |
---|---|
tintMode |
MenuItem!: the blending mode used to apply the tint, may be null to clear tint |
setNumericShortcut
static fun setNumericShortcut(item: MenuItem!, numericChar: Char, numericModifiers: Int): Unit
Change the numeric shortcut and modifiers associated with this item.
See Menu
for the menu types that support shortcuts.
Parameters | |
---|---|
numericChar |
MenuItem!: The numeric shortcut key. This is the shortcut when using a 12-key (numeric) keyboard. |
numericModifiers |
MenuItem!: The modifier associated with the shortcut. It should be a combination of KeyEvent#META_META_ON , KeyEvent#META_CTRL_ON , KeyEvent#META_ALT_ON , KeyEvent#META_SHIFT_ON , KeyEvent#META_SYM_ON , KeyEvent#META_FUNCTION_ON . |
setOnActionExpandListener
static funsetOnActionExpandListener(item: MenuItem!, listener: MenuItemCompat.OnActionExpandListener!): MenuItem!
Deprecated: Use MenuItem#setOnActionExpandListener(MenuItem.OnActionExpandListener)
directly.
Set an 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
.
Parameters | |
---|---|
listener |
MenuItem!: Listener that will respond to expand/collapse events |
Return | |
---|---|
MenuItem!: This menu item instance for call chaining |
setShortcut
static fun setShortcut(item: MenuItem!, numericChar: Char, alphaChar: Char, numericModifiers: Int, alphaModifiers: Int): Unit
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 corresponding modifier key. Also note that case is not significant and that alphabetic shortcut characters will be handled in lower case.
See Menu
for the menu types that support shortcuts.
Parameters | |
---|---|
numericChar |
MenuItem!: The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard. |
numericModifiers |
MenuItem!: The numeric modifier associated with the shortcut. It should be a combination of KeyEvent#META_META_ON , KeyEvent#META_CTRL_ON , KeyEvent#META_ALT_ON , KeyEvent#META_SHIFT_ON , KeyEvent#META_SYM_ON , KeyEvent#META_FUNCTION_ON . |
alphaChar |
MenuItem!: The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys. |
alphaModifiers |
MenuItem!: The alphabetic modifier associated with the shortcut. It should be a combination of KeyEvent#META_META_ON , KeyEvent#META_CTRL_ON , KeyEvent#META_ALT_ON , KeyEvent#META_SHIFT_ON , KeyEvent#META_SYM_ON , KeyEvent#META_FUNCTION_ON . |
setShowAsAction
static funsetShowAsAction(item: MenuItem!, actionEnum: Int): Unit
Deprecated: Use MenuItem#setShowAsAction(int)
directly.
Sets how this item should display in the presence of a compatible Action Bar. If the given item is compatible, this will call the item's supported implementation of MenuItem#setShowAsAction(int)
.
Parameters | |
---|---|
item |
MenuItem!: - the item to change |
actionEnum |
MenuItem!: - How the item should display. |
setTooltipText
static fun setTooltipText(item: MenuItem!, tooltipText: CharSequence!): Unit
Change the tooltip text associated with this menu item.
Parameters | |
---|---|
item |
MenuItem!: item to change. |
tooltipText |
MenuItem!: The new tooltip text |