# 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)

*** ** * ** ***


```
public class Action
```

<br />

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

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

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

|---|---|
| `https://developer.android.com/reference/androidx/leanback/widget/GuidedDatePickerAction` | Subclass of GuidedAction that can choose a date. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.ClosedCaptioningAction` | An action for displaying a CC (Closed Captioning) icon. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.FastForwardAction` | An action displaying an icon for fast forward. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.HighQualityAction` | An action for displaying a HQ (High Quality) icon. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.PlayPauseAction` | An action displaying icons for play and pause. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.RepeatAction` | An action for displaying three repeat states: none, one, or all. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.RewindAction` | An action displaying an icon for rewind. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.ShuffleAction` | An action for displaying a shuffle icon. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.ThumbsAction` | A base class for displaying a thumbs action. |
| `https://developer.android.com/reference/androidx/leanback/widget/PlaybackControlsRow.ThumbsDownAction` | An action displaying an icon for thumbs down. |
| `https://developer.android.com/reference/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 |
|---|---|
| `static final long` | `https://developer.android.com/reference/androidx/leanback/widget/Action#NO_ID() = -1` Indicates that an id has not been set. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/leanback/widget/Action#Action(long)(long id)` Constructor for an Action. |
| `https://developer.android.com/reference/androidx/leanback/widget/Action#Action(long,java.lang.CharSequence)(long id, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label)` Constructor for an Action. |
| `https://developer.android.com/reference/androidx/leanback/widget/Action#Action(long,java.lang.CharSequence,java.lang.CharSequence)( long id, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label1, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label2 )` Constructor for an Action. |
| `https://developer.android.com/reference/androidx/leanback/widget/Action#Action(long,java.lang.CharSequence,java.lang.CharSequence,android.graphics.drawable.Drawable)( long id, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label1, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label2, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html icon )` Constructor for an Action. |

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/Action#addKeyCode(int)(int keyCode)` Adds a keycode used to invoke this Action. |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/leanback/widget/Action#getIcon()()` Returns the icon drawable for this Action. |
| `final long` | `https://developer.android.com/reference/androidx/leanback/widget/Action#getId()()` Returns the id for this Action. |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/leanback/widget/Action#getLabel1()()` Returns the first line label for this Action. |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/leanback/widget/Action#getLabel2()()` Returns the second line label for this Action. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/Action#removeKeyCode(int)(int keyCode)` Removes a keycode used to invoke this Action. |
| `final boolean` | `https://developer.android.com/reference/androidx/leanback/widget/Action#respondsToKeyCode(int)(int keyCode)` Returns true if the Action should respond to the given keycode. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/Action#setIcon(android.graphics.drawable.Drawable)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html icon)` Sets the icon drawable for this Action. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/Action#setId(long)(long id)` Sets the id for this Action. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/Action#setLabel1(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label)` Sets the first line label for this Action. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/Action#setLabel2(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label)` Sets the second line label for this Action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/leanback/widget/Action#toString()()` |

## Constants

### NO_ID

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

```
public static final long NO_ID = -1
```

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)

```
public Action(long id)
```

Constructor for an Action.

| Parameters |
|---|---|
| `long id` | The id of the Action. |

### Action

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

```
public Action(long id, @Nullable CharSequence label)
```

Constructor for an Action.

| Parameters |
|---|---|
| `long id` | The id of the Action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label` | The label to display for the Action. |

### Action

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

```
public Action(
    long id,
    @Nullable CharSequence label1,
    @Nullable CharSequence label2
)
```

Constructor for an Action.

| Parameters |
|---|---|
| `long id` | The id of the Action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label1` | The label to display on the first line of the Action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label2` | 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)

```
public Action(
    long id,
    @Nullable CharSequence label1,
    @Nullable CharSequence label2,
    @Nullable Drawable icon
)
```

Constructor for an Action.

| Parameters |
|---|---|
| `long id` | The id of the Action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label1` | The label to display on the first line of the Action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html label2` | The label to display on the second line of the Action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html icon` | The icon to display for the Action. |

## Public methods

### addKeyCode

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

```
public final void addKeyCode(int keyCode)
```

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)

```
public final @Nullable Drawable getIcon()
```

Returns the icon drawable for this Action.

### getId

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

```
public final long getId()
```

Returns the id for this Action.

### getLabel1

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

```
public final @Nullable CharSequence getLabel1()
```

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)

```
public final @Nullable CharSequence getLabel2()
```

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)

```
public final void removeKeyCode(int keyCode)
```

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)

```
public final boolean respondsToKeyCode(int keyCode)
```

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)

```
public final void setIcon(@Nullable Drawable icon)
```

Sets the icon drawable for this Action.

### setId

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

```
public final void setId(long id)
```

Sets the id for this Action.

### setLabel1

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

```
public final void setLabel1(@Nullable CharSequence label)
```

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)

```
public final void setLabel2(@Nullable CharSequence label)
```

Sets the second line label for this Action.

### toString

```
public @NonNull String toString()
```