# Action

# Action

Artifact: [androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback)  
[View Source](https://cs.android.com/search?q=file:androidx/leanback/widget/Action.java+class:androidx.leanback.widget.Action)  
Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/leanback/widget/Action "View this page in Java")


```
class Action
```

<br />

Known direct subclasses  
[GuidedAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/GuidedAction), [PlaybackControlsRow.MoreActions](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.MoreActions), [PlaybackControlsRow.MultiAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.MultiAction), [PlaybackControlsRow.PictureInPictureAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.PictureInPictureAction), [PlaybackControlsRow.SkipNextAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.SkipNextAction), [PlaybackControlsRow.SkipPreviousAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.SkipPreviousAction)  

|------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [GuidedAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/GuidedAction)                                                             | A data class which represents an action within a [androidx.leanback.app.GuidedStepFragment](https://developer.android.com/reference/kotlin/androidx/leanback/app/GuidedStepFragment). |
| [PlaybackControlsRow.MoreActions](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.MoreActions)                       | An action displaying an icon for "more actions".                                                                                                                                      |
| [PlaybackControlsRow.MultiAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.MultiAction)                       | Base class for an action comprised of a series of icons.                                                                                                                              |
| [PlaybackControlsRow.PictureInPictureAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.PictureInPictureAction) | An action displaying an icon for picture-in-picture.                                                                                                                                  |
| [PlaybackControlsRow.SkipNextAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.SkipNextAction)                 | An action displaying an icon for skip next.                                                                                                                                           |
| [PlaybackControlsRow.SkipPreviousAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.SkipPreviousAction)         | An action displaying an icon for skip previous.                                                                                                                                       |

Known indirect subclasses  
[GuidedDatePickerAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/GuidedDatePickerAction), [PlaybackControlsRow.ClosedCaptioningAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ClosedCaptioningAction), [PlaybackControlsRow.FastForwardAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.FastForwardAction), [PlaybackControlsRow.HighQualityAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.HighQualityAction), [PlaybackControlsRow.PlayPauseAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.PlayPauseAction), [PlaybackControlsRow.RepeatAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.RepeatAction), [PlaybackControlsRow.RewindAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.RewindAction), [PlaybackControlsRow.ShuffleAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ShuffleAction), [PlaybackControlsRow.ThumbsAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ThumbsAction), [PlaybackControlsRow.ThumbsDownAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ThumbsDownAction), [PlaybackControlsRow.ThumbsUpAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ThumbsUpAction)  

|------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| [GuidedDatePickerAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/GuidedDatePickerAction)                                         | Subclass of GuidedAction that can choose a date.                 |
| [PlaybackControlsRow.ClosedCaptioningAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ClosedCaptioningAction) | An action for displaying a CC (Closed Captioning) icon.          |
| [PlaybackControlsRow.FastForwardAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.FastForwardAction)           | An action displaying an icon for fast forward.                   |
| [PlaybackControlsRow.HighQualityAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.HighQualityAction)           | An action for displaying a HQ (High Quality) icon.               |
| [PlaybackControlsRow.PlayPauseAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.PlayPauseAction)               | An action displaying icons for play and pause.                   |
| [PlaybackControlsRow.RepeatAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.RepeatAction)                     | An action for displaying three repeat states: none, one, or all. |
| [PlaybackControlsRow.RewindAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.RewindAction)                     | An action displaying an icon for rewind.                         |
| [PlaybackControlsRow.ShuffleAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ShuffleAction)                   | An action for displaying a shuffle icon.                         |
| [PlaybackControlsRow.ThumbsAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ThumbsAction)                     | A base class for displaying a thumbs action.                     |
| [PlaybackControlsRow.ThumbsDownAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ThumbsDownAction)             | An action displaying an icon for thumbs down.                    |
| [PlaybackControlsRow.ThumbsUpAction](https://developer.android.com/reference/kotlin/androidx/leanback/widget/PlaybackControlsRow.ThumbsUpAction)                 | An action displaying an icon for thumbs up.                      |

*** ** * ** ***

An action contains one or two lines of text, an optional image and an optional id. It may also be invoked by one or more keycodes.

## Summary

|                                     ### Constants                                     |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [NO_ID](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#NO_ID())` = -1` Indicates that an id has not been set. |

|                                                                                                                                                                                                                                                                                                       ### Public constructors                                                                                                                                                                                                                                                                                                        |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Action](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#Action(long))`(id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Constructor for an Action.                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Action](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#Action(long,java.lang.CharSequence))`(id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, label: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?)` Constructor for an Action.                                                                                                                                                                                                                                                                             |
| [Action](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#Action(long,java.lang.CharSequence,java.lang.CharSequence))`(id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, label1: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?, label2: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?)` Constructor for an Action.                                                                                                                                          |
| [Action](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#Action(long,java.lang.CharSequence,java.lang.CharSequence,android.graphics.drawable.Drawable))`(id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, label1: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?, label2: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?, icon: `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?)` Constructor for an Action. |

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [addKeyCode](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#addKeyCode(int))`(keyCode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Adds a keycode used to invoke this Action.                                     |
| [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?`    | [getIcon](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#getIcon())`()` Returns the icon drawable for this Action.                                                                                                                                    |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                     | [getId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#getId())`()` Returns the id for this Action.                                                                                                                                                   |
| [CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | [getLabel1](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#getLabel1())`()` Returns the first line label for this Action.                                                                                                                             |
| [CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | [getLabel2](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#getLabel2())`()` Returns the second line label for this Action.                                                                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [removeKeyCode](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#removeKeyCode(int))`(keyCode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Removes a keycode used to invoke this Action.                            |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)               | [respondsToKeyCode](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#respondsToKeyCode(int))`(keyCode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns true if the Action should respond to the given keycode.  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [setIcon](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#setIcon(android.graphics.drawable.Drawable))`(icon: `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?)` Sets the icon drawable for this Action. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [setId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#setId(long))`(id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Sets the id for this Action.                                                               |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [setLabel1](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#setLabel1(java.lang.CharSequence))`(label: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?)` Sets the first line label for this Action.  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [setLabel2](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#setLabel2(java.lang.CharSequence))`(label: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?)` Sets the second line label for this Action. |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                 | [toString](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Action#toString())`()`                                                                                                                                                                             |

## Constants

### NO_ID

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
const val NO_ID = -1: Long
```

Indicates that an id has not been set.  

## Public constructors

### Action

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
Action(id: Long)
```

Constructor for an Action.  

|                                     Parameters                                      |
|-------------------------------------------------------------------------------------|-----------------------|
| `id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The id of the Action. |

### Action

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
Action(id: Long, label: CharSequence?)
```

Constructor for an Action.  

|                                                 Parameters                                                 |
|------------------------------------------------------------------------------------------------------------|--------------------------------------|
| `id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                        | The id of the Action.                |
| `label: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | The label to display for the Action. |

### Action

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
Action(id: Long, label1: CharSequence?, label2: CharSequence?)
```

Constructor for an Action.  

|                                                 Parameters                                                  |
|-------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| `id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                         | The id of the Action.                                  |
| `label1: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | The label to display on the first line of the Action.  |
| `label2: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | The label to display on the second line of the Action. |

### Action

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
Action(id: Long, label1: CharSequence?, label2: CharSequence?, icon: Drawable?)
```

Constructor for an Action.  

|                                                 Parameters                                                  |
|-------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| `id: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                         | The id of the Action.                                  |
| `label1: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | The label to display on the first line of the Action.  |
| `label2: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | The label to display on the second line of the Action. |
| `icon: `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?`      | The icon to display for the Action.                    |

## Public functions

### addKeyCode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun addKeyCode(keyCode: Int): Unit
```

Adds a keycode used to invoke this Action.  

### getIcon

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getIcon(): Drawable?
```

Returns the icon drawable for this Action.  

### getId

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getId(): Long
```

Returns the id for this Action.  

### getLabel1

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getLabel1(): CharSequence?
```

Returns the first line label for this Action.  

### getLabel2

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getLabel2(): CharSequence?
```

Returns the second line label for this Action.  

### removeKeyCode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun removeKeyCode(keyCode: Int): Unit
```

Removes a keycode used to invoke this Action.  

### respondsToKeyCode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun respondsToKeyCode(keyCode: Int): Boolean
```

Returns true if the Action should respond to the given keycode.  

### setIcon

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun setIcon(icon: Drawable?): Unit
```

Sets the icon drawable for this Action.  

### setId

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun setId(id: Long): Unit
```

Sets the id for this Action.  

### setLabel1

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun setLabel1(label: CharSequence?): Unit
```

Sets the first line label for this Action.  

### setLabel2

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun setLabel2(label: CharSequence?): Unit
```

Sets the second line label for this Action.  

### toString

```
fun toString(): String
```