# Action

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/Action.java+class:androidx.car.app.model.Action) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
@CarProtocol
public final class Action
```

<br />

*** ** * ** ***

Represents an action with an optional icon and text.

Actions may be displayed differently depending on the template or model they are added to. For example, the host may decide to display an action as a floating action button (FAB) when displayed over a map, as a button when displayed in a `https://developer.android.com/reference/androidx/car/app/model/Pane`, or as a simple icon with no title when displayed within a `https://developer.android.com/reference/androidx/car/app/model/Row`.

#### Standard actions

A set of standard, built-in `https://developer.android.com/reference/androidx/car/app/model/Action` instances is available with a few of the common basic actions car apps may need (for example a `https://developer.android.com/reference/androidx/car/app/model/Action#BACK()` action).

With the exception of `https://developer.android.com/reference/androidx/car/app/model/Action#APP_ICON()` and `https://developer.android.com/reference/androidx/car/app/model/Action#BACK()`, an app can provide a custom title and icon for the action. However, depending on the template the action belongs to, the title or icon may be disallowed. If such restrictions apply, the documentation of the APIs that consume the action will note them accordingly.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/car/app/model/Action.Builder` A builder of `https://developer.android.com/reference/androidx/car/app/model/Action`. |

| ### Constants |
|---|---|
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action` | `https://developer.android.com/reference/androidx/car/app/model/Action#APP_ICON()` A standard action to show the app's icon. |
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action` | `https://developer.android.com/reference/androidx/car/app/model/Action#BACK()` A standard action to navigate back in the user interface. |
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 7) https://developer.android.com/reference/androidx/car/app/model/Action#COMPOSE_MESSAGE()` A standard action to show the message compose button |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 5) https://developer.android.com/reference/androidx/car/app/model/Action#FLAG_DEFAULT() = 4` Indicates that this action is the default action out of a set of other actions. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 5) https://developer.android.com/reference/androidx/car/app/model/Action#FLAG_IS_PERSISTENT() = 2` Indicates that this action will not fade in/out inside an `https://developer.android.com/reference/androidx/car/app/model/ActionStrip`. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 4) https://developer.android.com/reference/androidx/car/app/model/Action#FLAG_PRIMARY() = 1` Indicates that this action is the most important one, out of a set of other actions. |
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) @https://developer.android.com/reference/androidx/annotation/RequiresPermission(value = "androidx.car.app.MEDIA_TEMPLATES") https://developer.android.com/reference/androidx/car/app/model/Action#MEDIA_PLAYBACK()` A standard action to show the media playback button. |
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action` | `https://developer.android.com/reference/androidx/car/app/model/Action#PAN()` A standard action to toggle the pan mode in a map-based template. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/Action#TYPE_APP_ICON() = 65538` An action representing an app's icon. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/Action#TYPE_BACK() = 65539` An action to navigate back in the user interface. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 7) https://developer.android.com/reference/androidx/car/app/model/Action#TYPE_COMPOSE_MESSAGE() = 65541` An action to allow user compose a message. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/Action#TYPE_CUSTOM() = 1` An app-defined custom action type. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) @https://developer.android.com/reference/androidx/annotation/RequiresPermission(value = "androidx.car.app.MEDIA_TEMPLATES") https://developer.android.com/reference/androidx/car/app/model/Action#TYPE_MEDIA_PLAYBACK() = 65542` A standard action to show the media playback button. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/Action#TYPE_PAN() = 65540` An action to toggle the pan mode in a map-based template. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/Action#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html other)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/androidx/car/app/model/Action#getBackgroundColor()()` Returns the `https://developer.android.com/reference/androidx/car/app/model/CarColor` used for the background color of the action. |
| `int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 4) https://developer.android.com/reference/androidx/car/app/model/Action#getFlags()()` Returns flags affecting how this action should be treated |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarIcon` | `https://developer.android.com/reference/androidx/car/app/model/Action#getIcon()()` Returns the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` to display in the action or `null` if the action does not have an icon. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/OnClickDelegate` | `https://developer.android.com/reference/androidx/car/app/model/Action#getOnClickDelegate()()` Returns the `https://developer.android.com/reference/androidx/car/app/model/OnClickDelegate` that should be used for this action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarText` | `https://developer.android.com/reference/androidx/car/app/model/Action#getTitle()()` Returns the title displayed in the action or `null` if the action does not have a title. |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/Action#getType()()` Returns the type of the action. |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/Action#hashCode()()` |
| `boolean` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 5) https://developer.android.com/reference/androidx/car/app/model/Action#isEnabled()()` Returns `true` if the action is enabled. |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/Action#isStandard()()` Returns whether the action is a standard action such as `https://developer.android.com/reference/androidx/car/app/model/Action#BACK()`. |
| `@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/car/app/model/Action#toString()()` |
| `static @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/car/app/model/Action#typeToString(int)(int type)` Converts the given `type` into a string representation. |

## Constants

### APP_ICON

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public static final @NonNull Action APP_ICON
```

A standard action to show the app's icon.

This action is non-interactive.

### BACK

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public static final @NonNull Action BACK
```

A standard action to navigate back in the user interface.

The default behavior for a back press will call `https://developer.android.com/reference/androidx/car/app/ScreenManager#pop()`.

To override the default behavior, register a `https://developer.android.com/reference/androidx/activity/OnBackPressedCallback` via `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher#addCallback(androidx.lifecycle.LifecycleOwner,androidx.activity.OnBackPressedCallback)`, which you can retrieve from `https://developer.android.com/reference/androidx/car/app/CarContext#getOnBackPressedDispatcher()`.

### COMPOSE_MESSAGE

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 7)
public static final @NonNull Action COMPOSE_MESSAGE
```

A standard action to show the message compose button

This action is interactive.

### FLAG_DEFAULT

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.3.0)

```
@RequiresCarApi(value = 5)
public static final int FLAG_DEFAULT = 4
```

Indicates that this action is the default action out of a set of other actions.

The action with this flag may be treated differently by the host depending on where they are used. For example, it may be set as the default action to be triggered when the Alerter times out in the AlertCard. The first action with the FLAG_DEFAULT in an action list will be treated as the Default Action. See the documentation on where the `https://developer.android.com/reference/androidx/car/app/model/Action` is added for more details on any restriction(s) that might apply.

### FLAG_IS_PERSISTENT

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.2.0)

```
@RequiresCarApi(value = 5)
public static final int FLAG_IS_PERSISTENT = 2
```

Indicates that this action will not fade in/out inside an `https://developer.android.com/reference/androidx/car/app/model/ActionStrip`.

### FLAG_PRIMARY

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

```
@RequiresCarApi(value = 4)
public static final int FLAG_PRIMARY = 1
```

Indicates that this action is the most important one, out of a set of other actions.

The action with this flag may be treated differently by the host depending on where they are used. For example, it may be colored or ordered differently to align with the vehicle's look and feel. See the documentation on where the `https://developer.android.com/reference/androidx/car/app/model/Action` is added for more details on any restriction(s) that might apply.

### MEDIA_PLAYBACK

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
@RequiresCarApi(value = 8)
@RequiresPermission(value = "androidx.car.app.MEDIA_TEMPLATES")
public static final @NonNull Action MEDIA_PLAYBACK
```

A standard action to show the media playback button.

Note: ONLY apps with `https://developer.android.com/reference/androidx/car/app/CarAppPermission#MEDIA_TEMPLATES()` can use this action.

Starting in Car API 9, this action can ONLY be used inside a `https://developer.android.com/reference/androidx/car/app/model/Row#mActions()` to indicate the currently playing song. If used as a floating action button on Car API 9+ hosts, it will be ignored, so developers should not set it as a floating action button. For Car API 8, this action continues to be supported as a floating action button in browse views or inside a row.

### PAN

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

```
public static final @NonNull Action PAN
```

A standard action to toggle the pan mode in a map-based template.

If the app does not provide a custom icon, a default pan icon will be used.

You can set a custom icon in a pan action with the following code:

```
Action panAction = new Action.Builder(Action.PAN).setIcon(customIcon).build();
```

### TYPE_APP_ICON

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public static final int TYPE_APP_ICON = 65538
```

An action representing an app's icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/Action#APP_ICON()` |   |

### TYPE_BACK

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public static final int TYPE_BACK = 65539
```

An action to navigate back in the user interface.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/Action#BACK()` |   |

### TYPE_COMPOSE_MESSAGE

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 7)
public static final int TYPE_COMPOSE_MESSAGE = 65541
```

An action to allow user compose a message.

### TYPE_CUSTOM

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public static final int TYPE_CUSTOM = 1
```

An app-defined custom action type.

### TYPE_MEDIA_PLAYBACK

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
@RequiresCarApi(value = 8)
@RequiresPermission(value = "androidx.car.app.MEDIA_TEMPLATES")
public static final int TYPE_MEDIA_PLAYBACK = 65542
```

A standard action to show the media playback button.

Note: ONLY apps with `https://developer.android.com/reference/androidx/car/app/CarAppPermission#MEDIA_TEMPLATES()` can use this action.

Starting in Car API 9, this action can ONLY be used inside a `https://developer.android.com/reference/androidx/car/app/model/Row#mActions()` to indicate the currently playing song. If used as a floating action button on Car API 9+ hosts, it will be ignored, so developers should not set it as a floating action button. For Car API 8, this action continues to be supported as a floating action button in browse views or inside a row.

### TYPE_PAN

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

```
public static final int TYPE_PAN = 65540
```

An action to toggle the pan mode in a map-based template.

## Public methods

### equals

```
public boolean equals(@Nullable Object other)
```

### getBackgroundColor

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable CarColor getBackgroundColor()
```

Returns the `https://developer.android.com/reference/androidx/car/app/model/CarColor` used for the background color of the action.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/Action.Builder#setBackgroundColor(androidx.car.app.model.CarColor)` |   |

### getFlags

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

```
@RequiresCarApi(value = 4)
public int getFlags()
```

Returns flags affecting how this action should be treated

### getIcon

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable CarIcon getIcon()
```

Returns the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` to display in the action or `null` if the action does not have an icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/Action.Builder#setIcon(androidx.car.app.model.CarIcon)` |   |

### getOnClickDelegate

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable OnClickDelegate getOnClickDelegate()
```

Returns the `https://developer.android.com/reference/androidx/car/app/model/OnClickDelegate` that should be used for this action.

### getTitle

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable CarText getTitle()
```

Returns the title displayed in the action or `null` if the action does not have a title.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/Action.Builder#setTitle(java.lang.CharSequence)` |   |

### getType

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public int getType()
```

Returns the type of the action.

### hashCode

```
public int hashCode()
```

### isEnabled

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.3.0)

```
@RequiresCarApi(value = 5)
public boolean isEnabled()
```

Returns `true` if the action is enabled.

### isStandard

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public boolean isStandard()
```

Returns whether the action is a standard action such as `https://developer.android.com/reference/androidx/car/app/model/Action#BACK()`.

### toString

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

### typeToString

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public static @NonNull String typeToString(int type)
```

Converts the given `type` into a string representation.