Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/view/ActionMode#nestedclasses) \| [Constants](https://developer.android.com/reference/android/view/ActionMode#constants) \| [Ctors](https://developer.android.com/reference/android/view/ActionMode#pubctors) \| [Methods](https://developer.android.com/reference/android/view/ActionMode#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/ActionMode#inhmethods)

# ActionMode

*** ** * ** ***


`
public


abstract
class
ActionMode
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.ActionMode |

<br />

*** ** * ** ***

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.

### Developer Guides

For information about how to provide contextual actions with `ActionMode`,
read the [Menus](https://developer.android.com/guide/topics/ui/menus#context-menu)
developer guide.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/view/ActionMode.Callback` Callback interface for action modes. |
| ` class` | `https://developer.android.com/reference/android/view/ActionMode.Callback2` Extension of `https://developer.android.com/reference/android/view/ActionMode.Callback` to provide content rect information. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/view/ActionMode#DEFAULT_HIDE_DURATION` Default value to hide the action mode for `https://developer.android.com/reference/android/view/ViewConfiguration#getDefaultActionModeHideDuration()`. |
| `int` | `https://developer.android.com/reference/android/view/ActionMode#TYPE_FLOATING` The action mode is treated as a Floating Toolbar. |
| `int` | `https://developer.android.com/reference/android/view/ActionMode#TYPE_PRIMARY` The action mode is treated as a Primary mode. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/ActionMode#ActionMode()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#clearTextSelection()() ` Clear the text selection. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/ActionMode#finish()() ` Finish and close this action mode. |
| ` abstract https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/view/ActionMode#getCustomView()() ` Returns the current custom view for this action mode. |
| ` abstract https://developer.android.com/reference/android/view/Menu` | ` https://developer.android.com/reference/android/view/ActionMode#getMenu()() ` Returns the menu of actions that this action mode presents. |
| ` abstract https://developer.android.com/reference/android/view/MenuInflater` | ` https://developer.android.com/reference/android/view/ActionMode#getMenuInflater()() ` Returns a `https://developer.android.com/reference/android/view/MenuInflater` with the ActionMode's context. |
| ` abstract https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/view/ActionMode#getSubtitle()() ` Returns the current subtitle of this action mode. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/android/view/ActionMode#getTag()() ` Retrieve the tag object associated with this ActionMode. |
| ` abstract https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/view/ActionMode#getTitle()() ` Returns the current title of this action mode. |
| ` boolean` | ` https://developer.android.com/reference/android/view/ActionMode#getTitleOptionalHint()() ` |
| ` int` | ` https://developer.android.com/reference/android/view/ActionMode#getType()() ` Returns the type for this action mode. |
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#hide(long)(long duration) ` Hide the action mode view from obstructing the content below for a short duration. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/ActionMode#invalidate()() ` Invalidate the action mode and refresh menu content. |
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#invalidateContentRect()() ` Invalidate the content rect associated to this ActionMode. |
| ` boolean` | ` https://developer.android.com/reference/android/view/ActionMode#isTitleOptional()() ` |
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#onWindowFocusChanged(boolean)(boolean hasWindowFocus) ` Called when the window containing the view that started this action mode gains or loses focus. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/ActionMode#setCustomView(android.view.View)(https://developer.android.com/reference/android/view/View view) ` Set a custom view for this action mode. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/ActionMode#setSubtitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence subtitle) ` Set the subtitle of the action mode. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/ActionMode#setSubtitle(int)(int resId) ` Set the subtitle of the action mode. |
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#setTag(java.lang.Object)(https://developer.android.com/reference/java/lang/Object tag) ` Set a tag object associated with this ActionMode. |
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#setTextSelection(java.lang.CharSequence,%20int,%20int,%20android.os.LocaleList)(https://developer.android.com/reference/java/lang/CharSequence text, int start, int end, https://developer.android.com/reference/android/os/LocaleList locales) ` Forward text selection data for ActionMode to process. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/ActionMode#setTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence title) ` Set the title of the action mode. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/ActionMode#setTitle(int)(int resId) ` Set the title of the action mode. |
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#setTitleOptionalHint(boolean)(boolean titleOptional) ` Set whether or not the title/subtitle display for this action mode is optional. |
| ` void` | ` https://developer.android.com/reference/android/view/ActionMode#setType(int)(int type) ` Set a type for this action mode. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Constants

### DEFAULT_HIDE_DURATION

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DEFAULT_HIDE_DURATION
```

Default value to hide the action mode for
`https://developer.android.com/reference/android/view/ViewConfiguration#getDefaultActionModeHideDuration()`.

<br />

Constant Value:

-1
(0xffffffff)


### TYPE_FLOATING

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int TYPE_FLOATING
```

The action mode is treated as a Floating Toolbar.
Use with `https://developer.android.com/reference/android/view/ActionMode#setType(int)`.

<br />

Constant Value:

1
(0x00000001)


### TYPE_PRIMARY

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int TYPE_PRIMARY
```

The action mode is treated as a Primary mode. This is the default.
Use with `https://developer.android.com/reference/android/view/ActionMode#setType(int)`.

<br />

Constant Value:

0
(0x00000000)


## Public constructors

### ActionMode

```
public ActionMode ()
```

<br />

<br />

## Public methods

### clearTextSelection

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void clearTextSelection ()
```

Clear the text selection. The method is called when the previous text selection needs to be
cleared. Calling it will also clear the actions resulted from previous text selection set by
setTextSelection.

<br />

### finish

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void finish ()
```

Finish and close this action mode. The action mode's `https://developer.android.com/reference/android/view/ActionMode.Callback` will
have its `https://developer.android.com/reference/android/view/ActionMode.Callback#onDestroyActionMode(android.view.ActionMode)` method called.

<br />

### getCustomView

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract View getCustomView ()
```

Returns the current custom view for this action mode.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/View` | The current custom view <br /> |

### getMenu

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract Menu getMenu ()
```

Returns the menu of actions that this action mode presents.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/Menu` | The action mode's menu. <br /> |

### getMenuInflater

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract MenuInflater getMenuInflater ()
```

Returns a `https://developer.android.com/reference/android/view/MenuInflater` with the ActionMode's context.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/MenuInflater` | <br /> |

### getSubtitle

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract CharSequence getSubtitle ()
```

Returns the current subtitle of this action mode.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | Subtitle text <br /> |

### getTag

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object getTag ()
```

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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | Tag associated with this ActionMode <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#setTag(java.lang.Object)`

### getTitle

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract CharSequence getTitle ()
```

Returns the current title of this action mode.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | Title text <br /> |

### getTitleOptionalHint

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean getTitleOptionalHint ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | true if this action mode has been given a hint to consider the title/subtitle display to be optional. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#setTitleOptionalHint(boolean)`
- `https://developer.android.com/reference/android/view/ActionMode#isTitleOptional()`

### getType

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getType ()
```

Returns the type for this action mode.

<br />

| Returns ||
|---|---|
| `int` | One of `https://developer.android.com/reference/android/view/ActionMode#TYPE_PRIMARY` or `https://developer.android.com/reference/android/view/ActionMode#TYPE_FLOATING`. <br /> |

### hide

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void hide (long duration)
```

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.

<br />

| Parameters ||
|---|---|
| `duration` | `long`: The number of milliseconds to hide for. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#DEFAULT_HIDE_DURATION`

### invalidate

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void invalidate ()
```

Invalidate the action mode and refresh menu content. The mode's
`https://developer.android.com/reference/android/view/ActionMode.Callback` will have its
`https://developer.android.com/reference/android/view/ActionMode.Callback#onPrepareActionMode(android.view.ActionMode,%20android.view.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.

<br />

### invalidateContentRect

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void invalidateContentRect ()
```

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.

<br />

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode.Callback2#onGetContentRect(android.view.ActionMode,%20android.view.View,%20android.graphics.Rect)`

### isTitleOptional

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isTitleOptional ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | true if this action mode considers the title and subtitle fields as optional. Optional titles may not be displayed to the user. <br /> |

### onWindowFocusChanged

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onWindowFocusChanged (boolean hasWindowFocus)
```

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

<br />

| Parameters ||
|---|---|
| `hasWindowFocus` | `boolean`: True if the window containing the view that started this action mode now has focus, false otherwise. <br /> |

### setCustomView

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setCustomView (View view)
```

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.

<br />

| Parameters ||
|---|---|
| `view` | `View`: Custom view to use in place of the title/subtitle. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#setTitle(java.lang.CharSequence)`
- `https://developer.android.com/reference/android/view/ActionMode#setSubtitle(java.lang.CharSequence)`

### setSubtitle

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setSubtitle (CharSequence subtitle)
```

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

<br />

| Parameters ||
|---|---|
| `subtitle` | `CharSequence`: Subtitle string to set <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#setSubtitle(int)`
- `https://developer.android.com/reference/android/view/ActionMode#setCustomView(android.view.View)`

### setSubtitle

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setSubtitle (int resId)
```

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

<br />

| Parameters ||
|---|---|
| `resId` | `int`: Resource ID of a string to set as the subtitle <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#setSubtitle(java.lang.CharSequence)`
- `https://developer.android.com/reference/android/view/ActionMode#setCustomView(android.view.View)`

### setTag

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setTag (Object tag)
```

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.

<br />

| Parameters ||
|---|---|
| `tag` | `Object`: Tag to associate with this ActionMode <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#getTag()`

### setTextSelection

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void setTextSelection (CharSequence text, 
                int start, 
                int end, 
                LocaleList locales)
```

Forward text selection data for ActionMode to process. The method is called when text
selection changes. An implementation of this API processes the text selection data such as
running the text classification task and handles the resulting actions, rendering them in the
action bar.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: The text of the text view. If the text is empty or null, it clears the previous text selection and its action classification results, equivalent to calling clearTextSelection(). <br /> |
| `start` | `int`: The start of the selection. If this parameter is \< 0 or \> end, it throws an IllegalArgumentException. <br /> |
| `end` | `int`: The end of the selection. If this parameter is \< 0 or \< start, it throws an IllegalArgumentException. <br /> |
| `locales` | `LocaleList`: The locales of the texts/view/selection. If it is empty, a default/unknown locale will be used. This value cannot be `null`. <br /> |

### setTitle

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setTitle (CharSequence title)
```

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

<br />

| Parameters ||
|---|---|
| `title` | `CharSequence`: Title string to set <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#setTitle(int)`
- `https://developer.android.com/reference/android/view/ActionMode#setCustomView(android.view.View)`

### setTitle

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void setTitle (int resId)
```

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

<br />

| Parameters ||
|---|---|
| `resId` | `int`: Resource ID of a string to set as the title <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ActionMode#setTitle(java.lang.CharSequence)`
- `https://developer.android.com/reference/android/view/ActionMode#setCustomView(android.view.View)`

### setTitleOptionalHint

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setTitleOptionalHint (boolean titleOptional)
```

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.

<br />

<br />

| Parameters ||
|---|---|
| `titleOptional` | `boolean`: true if the title only presents optional information. <br /> |

### setType

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setType (int type)
```

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

<br />

| Parameters ||
|---|---|
| `type` | `int`: One of `https://developer.android.com/reference/android/view/ActionMode#TYPE_PRIMARY` or `https://developer.android.com/reference/android/view/ActionMode#TYPE_FLOATING`. <br /> |