MenuItemCompat

Added in 1.1.0

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 , but take a MenuItem object as an additional argument.

Summary

Nested types

This interface is deprecated.

Use MenuItem.OnActionExpandListener directly.

Constants

const Int

This property is deprecated.

Use SHOW_AS_ACTION_ALWAYS directly.

const Int

This property is deprecated.

Use SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW directly.

const Int

This property is deprecated.

Use SHOW_AS_ACTION_IF_ROOM directly.

const Int

This property is deprecated.

Use SHOW_AS_ACTION_NEVER directly.

const Int

This property is deprecated.

Use SHOW_AS_ACTION_WITH_TEXT directly.

Public functions

java-static Boolean
@ReplaceWith(expression = "item.collapseActionView()")
collapseActionView(item: MenuItem!)

This function is deprecated.

Use collapseActionView directly.

java-static Boolean
@ReplaceWith(expression = "item.expandActionView()")
expandActionView(item: MenuItem!)

This function is deprecated.

Use expandActionView directly.

java-static ActionProvider?

Gets the ActionProvider.

java-static View!
@ReplaceWith(expression = "item.getActionView()")
getActionView(item: MenuItem!)

This function is deprecated.

Use getActionView directly.

java-static Int

Return the modifier for this menu item's alphabetic shortcut.

java-static CharSequence?

Retrieve the content description associated with this menu item.

java-static ColorStateList?
java-static PorterDuff.Mode?

Returns the blending mode used to apply the tint to the item's icon, if specified.

java-static Int

Return the modifiers for this menu item's numeric (12-key) shortcut.

java-static CharSequence?

Retrieve the tooltip text associated with this menu item.

java-static Boolean
@ReplaceWith(expression = "item.isActionViewExpanded()")
isActionViewExpanded(item: MenuItem!)

This function is deprecated.

Use isActionViewExpanded directly.

java-static MenuItem?

Sets the ActionProvider responsible for creating an action view if the item is placed on the action bar.

java-static MenuItem!
@ReplaceWith(expression = "item.setActionView(resId)")
setActionView(item: MenuItem!, resId: Int)

This function is deprecated.

Use setActionView directly.

java-static MenuItem!
@ReplaceWith(expression = "item.setActionView(view)")
setActionView(item: MenuItem!, view: View!)

This function is deprecated.

Use setActionView directly.

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

Applies a tint to the item's icon.

java-static Unit

Specifies the blending mode used to apply the tint specified by setIconTintList to the item's icon.

java-static Unit
setNumericShortcut(
    item: MenuItem,
    numericChar: Char,
    numericModifiers: Int
)

Change the numeric shortcut and modifiers associated with this item.

java-static MenuItem!

This function is deprecated.

Use setOnActionExpandListener directly.

java-static Unit
setShortcut(
    item: MenuItem,
    numericChar: Char,
    alphaChar: Char,
    numericModifiers: Int,
    alphaModifiers: Int
)

Change both the numeric and alphabetic shortcut associated with this item.

java-static Unit
@ReplaceWith(expression = "item.setShowAsAction(actionEnum)")
setShowAsAction(item: MenuItem!, actionEnum: Int)

This function is deprecated.

Use setShowAsAction directly.

java-static Unit
setTooltipText(item: MenuItem, tooltipText: CharSequence?)

Change the tooltip text associated with this menu item.

Constants

SHOW_AS_ACTION_ALWAYS

Added in 1.1.0
Deprecated in 1.1.0
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.

SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

Added in 1.1.0
Deprecated in 1.1.0
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.

SHOW_AS_ACTION_IF_ROOM

Added in 1.1.0
Deprecated in 1.1.0
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.

SHOW_AS_ACTION_NEVER

Added in 1.1.0
Deprecated in 1.1.0
const val SHOW_AS_ACTION_NEVER = 0: Int

Never show this item as a button in an Action Bar.

SHOW_AS_ACTION_WITH_TEXT

Added in 1.1.0
Deprecated in 1.1.0
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

collapseActionView

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "item.collapseActionView()")
java-static fun collapseActionView(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.

expandActionView

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "item.expandActionView()")
java-static fun expandActionView(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

Added in 1.1.0
java-static fun getActionProvider(item: MenuItem): ActionProvider?

Gets the ActionProvider.

Returns
ActionProvider?

The action provider.

getActionView

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "item.getActionView()")
java-static fun getActionView(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

Added in 1.1.0
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

Added in 1.1.0
java-static fun getContentDescription(item: MenuItem): CharSequence?

Retrieve the content description associated with this menu item.

Returns
CharSequence?

The content description.

getIconTintList

Added in 1.1.0
java-static fun getIconTintList(item: MenuItem): ColorStateList?
Returns
ColorStateList?

the tint applied to the item's icon

See also
setIconTintList

getIconTintMode

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
java-static fun getTooltipText(item: MenuItem): CharSequence?

Retrieve the tooltip text associated with this menu item.

Returns
CharSequence?

The tooltip text.

isActionViewExpanded

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "item.isActionViewExpanded()")
java-static fun isActionViewExpanded(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

Added in 1.1.0
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

setActionView

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "item.setActionView(resId)")
java-static fun setActionView(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

setActionView

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "item.setActionView(view)")
java-static fun setActionView(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

Added in 1.1.0
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 META_META_ON, META_CTRL_ON, META_ALT_ON, META_SHIFT_ON, META_SYM_ON, META_FUNCTION_ON.

setContentDescription

Added in 1.1.0
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

Added in 1.1.0
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 null to clear tint

See also
getIconTintList

setIconTintMode

Added in 1.1.0
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 null to clear tint

See also
setIconTintList

setNumericShortcut

Added in 1.1.0
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 META_META_ON, META_CTRL_ON, META_ALT_ON, META_SHIFT_ON, META_SYM_ON, META_FUNCTION_ON.

setOnActionExpandListener

Added in 1.1.0
Deprecated in 1.1.0
java-static fun setOnActionExpandListener(
    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

Added in 1.1.0
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 META_META_ON, META_CTRL_ON, META_ALT_ON, META_SHIFT_ON, META_SYM_ON, META_FUNCTION_ON.

alphaModifiers: Int

The alphabetic modifier associated with the shortcut. It should be a combination of META_META_ON, META_CTRL_ON, META_ALT_ON, META_SHIFT_ON, META_SYM_ON, META_FUNCTION_ON.

setShowAsAction

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "item.setShowAsAction(actionEnum)")
java-static fun setShowAsAction(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.

Parameters
item: MenuItem!

- the item to change

actionEnum: Int

- How the item should display.

setTooltipText

Added in 1.1.0
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