MenuItemCompat
class MenuItemCompat
Helper for accessing features in MenuItem.
Note: You cannot get an instance of this class. Instead, it provides static methods that correspond to the methods in MenuItem, but take a MenuItem object as an additional argument.
Summary
Nested types |
|---|
interface MenuItemCompat.OnActionExpandListenerThis interface is deprecated. Use |
Constants |
|
|---|---|
const Int |
This property is deprecated. Use |
const Int |
This property is deprecated. Use |
const Int |
This property is deprecated. Use |
const Int |
This property is deprecated. Use |
const Int |
This property is deprecated. Use |
Public functions |
|
|---|---|
java-static Boolean |
@ReplaceWith(expression = "item.collapseActionView()")This function is deprecated. Use |
java-static Boolean |
@ReplaceWith(expression = "item.expandActionView()")This function is deprecated. Use |
java-static ActionProvider? |
getActionProvider(item: MenuItem)Gets the |
java-static View! |
@ReplaceWith(expression = "item.getActionView()")This function is deprecated. Use |
java-static Int |
getAlphabeticModifiers(item: MenuItem)Return the modifier for this menu item's alphabetic shortcut. |
java-static CharSequence? |
getContentDescription(item: MenuItem)Retrieve the content description associated with this menu item. |
java-static ColorStateList? |
getIconTintList(item: MenuItem) |
java-static PorterDuff.Mode? |
getIconTintMode(item: MenuItem)Returns the blending mode used to apply the tint to the item's icon, if specified. |
java-static Int |
getNumericModifiers(item: MenuItem)Return the modifiers for this menu item's numeric (12-key) shortcut. |
java-static CharSequence? |
getTooltipText(item: MenuItem)Retrieve the tooltip text associated with this menu item. |
java-static Boolean |
@ReplaceWith(expression = "item.isActionViewExpanded()")This function is deprecated. Use |
java-static MenuItem? |
setActionProvider(item: MenuItem, provider: ActionProvider?)Sets the |
java-static MenuItem! |
@ReplaceWith(expression = "item.setActionView(resId)")This function is deprecated. Use |
java-static MenuItem! |
@ReplaceWith(expression = "item.setActionView(view)")This function is deprecated. Use |
java-static Unit |
setAlphabeticShortcut(item: MenuItem, alphaChar: Char, alphaModifiers: Int)Change the alphabetic shortcut associated with this item. |
java-static Unit |
setContentDescription(item: MenuItem, contentDescription: CharSequence?)Change the content description associated with this menu item. |
java-static Unit |
setIconTintList(item: MenuItem, tint: ColorStateList?)Applies a tint to the item's icon. |
java-static Unit |
setIconTintMode(item: MenuItem, tintMode: PorterDuff.Mode?)Specifies the blending mode used to apply the tint specified by |
java-static Unit |
setNumericShortcut(Change the numeric shortcut and modifiers associated with this item. |
java-static MenuItem! |
This function is deprecated. Use |
java-static Unit |
setShortcut(Change both the numeric and alphabetic shortcut associated with this item. |
java-static Unit |
@ReplaceWith(expression = "item.setShowAsAction(actionEnum)")This function is deprecated. Use |
java-static Unit |
setTooltipText(item: MenuItem, tooltipText: CharSequence?)Change the tooltip text associated with this menu item. |
Constants
const val SHOW_AS_ACTION_ALWAYS = 2: Int
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.
const val SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8: Int
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.
const val SHOW_AS_ACTION_IF_ROOM = 1: Int
Show this item as a button in an Action Bar if the system decides there is room for it.
const val SHOW_AS_ACTION_WITH_TEXT = 4: 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 functions
@ReplaceWith(expression = "item.collapseActionView()")
java-static funcollapseActionView(item: MenuItem!): Boolean
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 it will have its onMenuItemActionCollapse method invoked. The listener may return false from this method to prevent collapsing the action view.
| Returns | |
|---|---|
Boolean |
true if the action view was collapsed, false otherwise. |
@ReplaceWith(expression = "item.expandActionView()")
java-static funexpandActionView(item: MenuItem!): Boolean
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 it will have its onMenuItemActionExpand method invoked. The listener may return false from this method to prevent expanding the action view.
| Returns | |
|---|---|
Boolean |
true if the action view was expanded, false otherwise. |
getActionProvider
java-static fun getActionProvider(item: MenuItem): ActionProvider?
Gets the ActionProvider.
| Returns | |
|---|---|
ActionProvider? |
The action provider. |
| See also | |
|---|---|
ActionProvider |
|
setActionProvider |
@ReplaceWith(expression = "item.getActionView()")
java-static fungetActionView(item: MenuItem!): View!
Returns the currently set action view for this menu item.
| Parameters | |
|---|---|
item: MenuItem! |
the item to query |
| Returns | |
|---|---|
View! |
This item's action view |
getAlphabeticModifiers
java-static fun getAlphabeticModifiers(item: MenuItem): Int
Return the modifier for this menu item's alphabetic shortcut. The modifier is a combination of META_META_ON, META_CTRL_ON, META_ALT_ON, META_SHIFT_ON, META_SYM_ON, META_FUNCTION_ON. For example, META_FUNCTION_ON|META_CTRL_ON
| Returns | |
|---|---|
Int |
Modifier associated with the keyboard shortcut. |
getContentDescription
java-static fun getContentDescription(item: MenuItem): CharSequence?
Retrieve the content description associated with this menu item.
| Returns | |
|---|---|
CharSequence? |
The content description. |
getIconTintList
java-static fun getIconTintList(item: MenuItem): ColorStateList?
| Returns | |
|---|---|
ColorStateList? |
the tint applied to the item's icon |
| See also | |
|---|---|
setIconTintList |
getIconTintMode
java-static fun getIconTintMode(item: MenuItem): PorterDuff.Mode?
Returns the blending mode used to apply the tint to the item's icon, if specified.
| Returns | |
|---|---|
PorterDuff.Mode? |
the blending mode used to apply the tint to the item's icon |
| See also | |
|---|---|
setIconTintMode |
getNumericModifiers
java-static fun getNumericModifiers(item: MenuItem): Int
Return the modifiers for this menu item's numeric (12-key) shortcut. The modifier is a combination of META_META_ON, META_CTRL_ON, META_ALT_ON, META_SHIFT_ON, META_SYM_ON, META_FUNCTION_ON. For example, META_FUNCTION_ON|META_CTRL_ON
| Returns | |
|---|---|
Int |
Modifier associated with the numeric shortcut. |
getTooltipText
java-static fun getTooltipText(item: MenuItem): CharSequence?
Retrieve the tooltip text associated with this menu item.
| Returns | |
|---|---|
CharSequence? |
The tooltip text. |
@ReplaceWith(expression = "item.isActionViewExpanded()")
java-static funisActionViewExpanded(item: MenuItem!): Boolean
Returns true if this menu item's action view has been expanded.
| Returns | |
|---|---|
Boolean |
true if the item's action view is expanded, false otherwise. |
setActionProvider
java-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.
| Parameters | |
|---|---|
item: MenuItem |
item to change |
provider: ActionProvider? |
The action provider. |
| Returns | |
|---|---|
MenuItem? |
This Item so additional setters can be called. |
| See also | |
|---|---|
ActionProvider |
@ReplaceWith(expression = "item.setActionView(resId)")
java-static funsetActionView(item: MenuItem!, resId: Int): MenuItem!
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.
| Parameters | |
|---|---|
item: MenuItem! |
the item to change |
resId: Int |
Layout resource to use for presenting this item to the user. |
| Returns | |
|---|---|
MenuItem! |
This Item so additional setters can be called. |
| See also | |
|---|---|
setShowAsAction |
@ReplaceWith(expression = "item.setActionView(view)")
java-static funsetActionView(item: MenuItem!, view: View!): MenuItem!
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: View! |
View to use for presenting this item to the user. |
| Returns | |
|---|---|
MenuItem! |
This Item so additional setters can be called. |
| See also | |
|---|---|
setShowAsAction |
setAlphabeticShortcut
java-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 | |
|---|---|
item: MenuItem |
item for which to set the shortcut. |
alphaChar: Char |
The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys. |
alphaModifiers: Int |
The modifier associated with the shortcut. It should be a combination of |
setContentDescription
java-static fun setContentDescription(item: MenuItem, contentDescription: CharSequence?): Unit
Change the content description associated with this menu item.
| Parameters | |
|---|---|
item: MenuItem |
item to change. |
contentDescription: CharSequence? |
The new content description. |
setIconTintList
java-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 SRC_IN by default.
Subsequent calls to setIcon or setIcon will automatically mutate the icon and apply the specified tint and tint mode.
| Parameters | |
|---|---|
item: MenuItem |
item for which to set the tint. |
tint: ColorStateList? |
the tint to apply, may be |
| See also | |
|---|---|
getIconTintList |
setIconTintMode
java-static fun setIconTintMode(item: MenuItem, tintMode: PorterDuff.Mode?): Unit
Specifies the blending mode used to apply the tint specified by setIconTintList to the item's icon. The default mode is SRC_IN.
| Parameters | |
|---|---|
item: MenuItem |
item for which to set the tint mode. |
tintMode: PorterDuff.Mode? |
the blending mode used to apply the tint, may be |
| See also | |
|---|---|
setIconTintList |
setNumericShortcut
java-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 | |
|---|---|
item: MenuItem |
item for which to set the shortcut. |
numericChar: Char |
The numeric shortcut key. This is the shortcut when using a 12-key (numeric) keyboard. |
numericModifiers: Int |
The modifier associated with the shortcut. It should be a combination of |
java-static funsetOnActionExpandListener(
item: MenuItem!,
listener: MenuItemCompat.OnActionExpandListener!
): MenuItem!
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 | |
|---|---|
item: MenuItem! |
item on which to set the listener. |
listener: MenuItemCompat.OnActionExpandListener! |
Listener that will respond to expand/collapse events |
| Returns | |
|---|---|
MenuItem! |
This menu item instance for call chaining |
setShortcut
java-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 | |
|---|---|
item: MenuItem |
item for which to set the shortcut. |
numericChar: Char |
The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard. |
alphaChar: Char |
The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys. |
numericModifiers: Int |
The numeric modifier associated with the shortcut. It should be a combination of |
alphaModifiers: Int |
The alphabetic modifier associated with the shortcut. It should be a combination of |
@ReplaceWith(expression = "item.setShowAsAction(actionEnum)")
java-static funsetShowAsAction(item: MenuItem!, actionEnum: Int): Unit
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 setShowAsAction.
setTooltipText
java-static fun setTooltipText(item: MenuItem, tooltipText: CharSequence?): Unit
Change the tooltip text associated with this menu item.
| Parameters | |
|---|---|
item: MenuItem |
item to change. |
tooltipText: CharSequence? |
The new tooltip text |