Added in API level 11

ActionMode


abstract class ActionMode
kotlin.Any
   ↳ android.view.ActionMode

Represents a contextual mode of the user interface. Action modes can be used to provide alternative interaction modes and replace parts of the normal UI until finished. Examples of good action modes include text selection and contextual actions.

Summary

Nested classes
abstract

Callback interface for action modes.

abstract

Extension of ActionMode.Callback to provide content rect information.

Constants
static Int

Default value to hide the action mode for ViewConfiguration.getDefaultActionModeHideDuration().

static Int

The action mode is treated as a Floating Toolbar.

static Int

The action mode is treated as a Primary mode.

Public constructors

Public methods
abstract Unit

Finish and close this action mode.

abstract View!

Returns the current custom view for this action mode.

abstract Menu!

Returns the menu of actions that this action mode presents.

abstract MenuInflater!

Returns a MenuInflater with the ActionMode's context.

abstract CharSequence!

Returns the current subtitle of this action mode.

open Any!

Retrieve the tag object associated with this ActionMode.

abstract CharSequence!

Returns the current title of this action mode.

open Boolean

open Int

Returns the type for this action mode.

open Unit
hide(duration: Long)

Hide the action mode view from obstructing the content below for a short duration.

abstract Unit

Invalidate the action mode and refresh menu content.

open Unit

Invalidate the content rect associated to this ActionMode.

open Boolean

open Unit
onWindowFocusChanged(hasWindowFocus: Boolean)

Called when the window containing the view that started this action mode gains or loses focus.

abstract Unit

Set a custom view for this action mode.

abstract Unit
setSubtitle(resId: Int)

Set the subtitle of the action mode.

abstract Unit

Set the subtitle of the action mode.

open Unit
setTag(tag: Any!)

Set a tag object associated with this ActionMode.

abstract Unit
setTitle(resId: Int)

Set the title of the action mode.

abstract Unit

Set the title of the action mode.

open Unit
setTitleOptionalHint(titleOptional: Boolean)

Set whether or not the title/subtitle display for this action mode is optional.

open Unit
setType(type: Int)

Set a type for this action mode.

Constants

DEFAULT_HIDE_DURATION

Added in API level 23
static val DEFAULT_HIDE_DURATION: Int

Default value to hide the action mode for ViewConfiguration.getDefaultActionModeHideDuration().

Value: -1

TYPE_FLOATING

Added in API level 23
static val TYPE_FLOATING: Int

The action mode is treated as a Floating Toolbar. Use with setType.

Value: 1

TYPE_PRIMARY

Added in API level 23
static val TYPE_PRIMARY: Int

The action mode is treated as a Primary mode. This is the default. Use with setType.

Value: 0

Public constructors

ActionMode

ActionMode()

Public methods

finish

Added in API level 11
abstract fun finish(): Unit

Finish and close this action mode. The action mode's ActionMode.Callback will have its Callback.onDestroyActionMode(ActionMode) method called.

getCustomView

Added in API level 11
abstract fun getCustomView(): View!

Returns the current custom view for this action mode.

Return
View! The current custom view

getMenu

Added in API level 11
abstract fun getMenu(): Menu!

Returns the menu of actions that this action mode presents.

Return
Menu! The action mode's menu.

getMenuInflater

Added in API level 11
abstract fun getMenuInflater(): MenuInflater!

Returns a MenuInflater with the ActionMode's context.

getSubtitle

Added in API level 11
abstract fun getSubtitle(): CharSequence!

Returns the current subtitle of this action mode.

Return
CharSequence! Subtitle text

getTag

Added in API level 14
open fun getTag(): Any!

Retrieve the tag object associated with this ActionMode.

Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.

Return
Any! Tag associated with this ActionMode

See Also

getTitle

Added in API level 11
abstract fun getTitle(): CharSequence!

Returns the current title of this action mode.

Return
CharSequence! Title text

getTitleOptionalHint

Added in API level 16
open fun getTitleOptionalHint(): Boolean
Return
Boolean true if this action mode has been given a hint to consider the title/subtitle display to be optional.

getType

Added in API level 23
open fun getType(): Int

Returns the type for this action mode.

Return
Int One of TYPE_PRIMARY or TYPE_FLOATING.

hide

Added in API level 23
open fun hide(duration: Long): Unit

Hide the action mode view from obstructing the content below for a short duration. This only makes sense for action modes that support dynamic positioning on the screen. If this method is called again before the hide duration expires, the later hide call will cancel the former and then take effect. NOTE that there is an internal limit to how long the mode can be hidden for. It's typically about a few seconds.

Parameters
duration Long: The number of milliseconds to hide for.

invalidate

Added in API level 11
abstract fun invalidate(): Unit

Invalidate the action mode and refresh menu content. The mode's ActionMode.Callback will have its Callback.onPrepareActionMode(ActionMode, Menu) method called. If it returns true the menu will be scanned for updated content and any relevant changes will be reflected to the user.

invalidateContentRect

Added in API level 23
open fun invalidateContentRect(): Unit

Invalidate the content rect associated to this ActionMode. This only makes sense for action modes that support dynamic positioning on the screen, and provides a more efficient way to reposition it without invalidating the whole action mode.

isTitleOptional

Added in API level 16
open fun isTitleOptional(): Boolean
Return
Boolean true if this action mode considers the title and subtitle fields as optional. Optional titles may not be displayed to the user.

onWindowFocusChanged

Added in API level 23
open fun onWindowFocusChanged(hasWindowFocus: Boolean): Unit

Called when the window containing the view that started this action mode gains or loses focus.

Parameters
hasWindowFocus Boolean: True if the window containing the view that started this action mode now has focus, false otherwise.

setCustomView

Added in API level 11
abstract fun setCustomView(view: View!): Unit

Set a custom view for this action mode. The custom view will take the place of the title and subtitle. Useful for things like search boxes.

Parameters
view View!: Custom view to use in place of the title/subtitle.

setSubtitle

Added in API level 11
abstract fun setSubtitle(resId: Int): Unit

Set the subtitle of the action mode. This method will have no visible effect if a custom view has been set.

Parameters
resId Int: Resource ID of a string to set as the subtitle

setSubtitle

Added in API level 11
abstract fun setSubtitle(subtitle: CharSequence!): Unit

Set the subtitle of the action mode. This method will have no visible effect if a custom view has been set.

Parameters
subtitle CharSequence!: Subtitle string to set

setTag

Added in API level 14
open fun setTag(tag: Any!): Unit

Set a tag object associated with this ActionMode.

Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.

Parameters
tag Any!: Tag to associate with this ActionMode

See Also

setTitle

Added in API level 11
abstract fun setTitle(resId: Int): Unit

Set the title of the action mode. This method will have no visible effect if a custom view has been set.

Parameters
resId Int: Resource ID of a string to set as the title

setTitle

Added in API level 11
abstract fun setTitle(title: CharSequence!): Unit

Set the title of the action mode. This method will have no visible effect if a custom view has been set.

Parameters
title CharSequence!: Title string to set

setTitleOptionalHint

Added in API level 16
open fun setTitleOptionalHint(titleOptional: Boolean): Unit

Set whether or not the title/subtitle display for this action mode is optional.

In many cases the supplied title for an action mode is merely meant to add context and is not strictly required for the action mode to be useful. If the title is optional, the system may choose to hide the title entirely rather than truncate it due to a lack of available space.

Note that this is merely a hint; the underlying implementation may choose to ignore this setting under some circumstances.

Parameters
titleOptional Boolean: true if the title only presents optional information.

setType

Added in API level 23
open fun setType(type: Int): Unit

Set a type for this action mode. This will affect how the system renders the action mode if it has to.

Parameters
type Int: One of TYPE_PRIMARY or TYPE_FLOATING.