Added in API level 1

ContextMenu


interface ContextMenu : Menu

Extension of Menu for context menus providing functionality to modify the header of the context menu.

Context menus do not support item shortcuts and item icons.

To show a context menu on long click, most clients will want to call Activity.registerForContextMenu and override Activity.onCreateContextMenu.

Summary

Nested classes
abstract

Additional information regarding the creation of the context menu.

Inherited constants
Int CATEGORY_ALTERNATIVE

Category code for the order integer for items/groups that are alternative actions on the data that is currently displayed -- or/add this with your base value.

Int CATEGORY_CONTAINER

Category code for the order integer for items/groups that are part of a container -- or/add this with your base value.

Int CATEGORY_SECONDARY

Category code for the order integer for items/groups that are user-supplied secondary (infrequently used) options -- or/add this with your base value.

Int CATEGORY_SYSTEM

Category code for the order integer for items/groups that are provided by the system -- or/add this with your base value.

Int FIRST

First value for group and item identifier integers.

Int FLAG_ALWAYS_PERFORM_CLOSE

Flag for performShortcut(int,android.view.KeyEvent,int): if set, always close the menu after executing the shortcut. Closing the menu also resets the prepared state.

Int FLAG_APPEND_TO_GROUP

Flag for addIntentOptions: if set, do not automatically remove any existing menu items in the same group.

Int FLAG_PERFORM_NO_CLOSE

Flag for performShortcut: if set, do not close the menu after executing the shortcut.

Int NONE

Value to use for group and item identifier integers when you don't care about them.

Int SUPPORTED_MODIFIERS_MASK

A mask of all supported modifiers for MenuItem's keyboard shortcuts

Public methods
abstract Unit

Clears the header of the context menu.

abstract ContextMenu!

Sets the context menu header's icon to the icon given in icon Drawable.

abstract ContextMenu!
setHeaderIcon(iconRes: Int)

Sets the context menu header's icon to the icon given in iconRes resource id.

abstract ContextMenu!
setHeaderTitle(titleRes: Int)

Sets the context menu header's title to the title given in titleRes resource identifier.

abstract ContextMenu!

Sets the context menu header's title to the title given in title.

abstract ContextMenu!

Sets the header of the context menu to the View given in view.

Inherited functions
MenuItem! add(titleRes: Int)

Add a new item to the menu. This item displays the given title for its label.

MenuItem! add(groupId: Int, itemId: Int, order: Int, titleRes: Int)

Variation on add(int,int,int,java.lang.CharSequence) that takes a string resource identifier instead of the string itself.

MenuItem! add(groupId: Int, itemId: Int, order: Int, title: CharSequence!)

Add a new item to the menu. This item displays the given title for its label.

MenuItem! add(title: CharSequence!)

Add a new item to the menu. This item displays the given title for its label.

Int addIntentOptions(groupId: Int, itemId: Int, order: Int, caller: ComponentName!, specifics: Array<Intent!>!, intent: Intent!, flags: Int, outSpecificItems: Array<MenuItem!>!)

Add a group of menu items corresponding to actions that can be performed for a particular Intent. The Intent is most often configured with a null action, the data that the current activity is working with, and includes either the Intent.CATEGORY_ALTERNATIVE or Intent.CATEGORY_SELECTED_ALTERNATIVE to find activities that have said they would like to be included as optional action. You can, however, use any Intent you want.

See android.content.pm.PackageManager#queryIntentActivityOptions for more * details on the caller, specifics, and intent arguments. The list returned by that function is used to populate the resulting menu items.

All of the menu items of possible options for the intent will be added with the given group and id. You can use the group to control ordering of the items in relation to other items in the menu. Normally this function will automatically remove any existing items in the menu in the same group and place a divider above and below the added items; this behavior can be modified with the flags parameter. For each of the generated items MenuItem.setIntent is called to associate the appropriate Intent with the item; this means the activity will automatically be started for you without having to do anything else.

SubMenu! addSubMenu(titleRes: Int)

Add a new sub-menu to the menu. This item displays the given title for its label. To modify other attributes on the submenu's menu item, use SubMenu.getItem().

SubMenu! addSubMenu(groupId: Int, itemId: Int, order: Int, titleRes: Int)

Variation on addSubMenu(int,int,int,java.lang.CharSequence) that takes a string resource identifier for the title instead of the string itself.

SubMenu! addSubMenu(groupId: Int, itemId: Int, order: Int, title: CharSequence!)

Add a new sub-menu to the menu. This item displays the given title for its label. To modify other attributes on the submenu's menu item, use SubMenu.getItem().

Note that you can only have one level of sub-menus, i.e. you cannnot add a subMenu to a subMenu: An UnsupportedOperationException will be thrown if you try.

SubMenu! addSubMenu(title: CharSequence!)

Add a new sub-menu to the menu. This item displays the given title for its label. To modify other attributes on the submenu's menu item, use SubMenu.getItem().

Unit clear()

Remove all existing items from the menu, leaving it empty as if it had just been created.

Unit close()

Closes the menu, if open.

MenuItem! findItem(id: Int)

Return the menu item with a particular identifier.

MenuItem! getItem(index: Int)

Gets the menu item at the given index.

Boolean hasVisibleItems()

Return whether the menu currently has item items that are visible.

Boolean isShortcutKey(keyCode: Int, event: KeyEvent!)

Is a keypress one of the defined shortcut keys for this window.

Boolean performIdentifierAction(id: Int, flags: Int)

Execute the menu item action associated with the given menu identifier.

Boolean performShortcut(keyCode: Int, event: KeyEvent!, flags: Int)

Execute the menu item action associated with the given shortcut character.

Unit removeGroup(groupId: Int)

Remove all items in the given group.

Unit removeItem(id: Int)

Remove the item with the given identifier.

Unit setGroupCheckable(group: Int, checkable: Boolean, exclusive: Boolean)

Control whether a particular group of items can show a check mark. This is similar to calling MenuItem.setCheckable on all of the menu items with the given group identifier, but in addition you can control whether this group contains a mutually-exclusive set items. This should be called after the items of the group have been added to the menu.

Unit setGroupDividerEnabled(groupDividerEnabled: Boolean)

Enable or disable the group dividers.

Unit setGroupEnabled(group: Int, enabled: Boolean)

Enable or disable all menu items that are in the given group.

Unit setGroupVisible(group: Int, visible: Boolean)

Show or hide all menu items that are in the given group.

Unit setQwertyMode(isQwerty: Boolean)

Control whether the menu should be running in qwerty mode (alphabetic shortcuts) or 12-key mode (numeric shortcuts).

Int size()

Get the number of items in the menu. Note that this will change any times items are added or removed from the menu.

Public methods

clearHeader

Added in API level 1
abstract fun clearHeader(): Unit

Clears the header of the context menu.

setHeaderIcon

Added in API level 1
abstract fun setHeaderIcon(icon: Drawable!): ContextMenu!

Sets the context menu header's icon to the icon given in icon Drawable.

Parameters
icon Drawable!: The Drawable used for the icon.
Return
ContextMenu! This ContextMenu so additional setters can be called.

setHeaderIcon

Added in API level 1
abstract fun setHeaderIcon(iconRes: Int): ContextMenu!

Sets the context menu header's icon to the icon given in iconRes resource id.

Parameters
iconRes Int: The resource identifier used for the icon.
Return
ContextMenu! This ContextMenu so additional setters can be called.

setHeaderTitle

Added in API level 1
abstract fun setHeaderTitle(titleRes: Int): ContextMenu!

Sets the context menu header's title to the title given in titleRes resource identifier.

Parameters
titleRes Int: The string resource identifier used for the title.
Return
ContextMenu! This ContextMenu so additional setters can be called.

setHeaderTitle

Added in API level 1
abstract fun setHeaderTitle(title: CharSequence!): ContextMenu!

Sets the context menu header's title to the title given in title.

Parameters
title CharSequence!: The character sequence used for the title.
Return
ContextMenu! This ContextMenu so additional setters can be called.

setHeaderView

Added in API level 1
abstract fun setHeaderView(view: View!): ContextMenu!

Sets the header of the context menu to the View given in view. This replaces the header title and icon (and those replace this).

Parameters
view View!: The View used for the header.
Return
ContextMenu! This ContextMenu so additional setters can be called.