Action


@CarProtocol
class Action


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 Pane, or as a simple icon with no title when displayed within a Row.

Standard actions A set of standard, built-in Action instances is available with a few of the common basic actions car apps may need (for example a BACK action).

With the exception of APP_ICON and 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

A builder of Action.

Constants

const Action

A standard action to show the app's icon.

const Action

A standard action to navigate back in the user interface.

const Action

A standard action to show the message compose button

const Int
@RequiresCarApi(value = 5)
FLAG_DEFAULT = 4

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

const Int

Indicates that this action will not fade in/out inside an ActionStrip.

const Int
@RequiresCarApi(value = 4)
FLAG_PRIMARY = 1

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

const Action

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

const Int

An action representing an app's icon.

const Int
TYPE_BACK = 65539

An action to navigate back in the user interface.

const Int

An action to allow user compose a message.

const Int

An app-defined custom action type.

const Int
TYPE_PAN = 65540

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

Public functions

Boolean
equals(other: Any?)
CarColor?

Returns the CarColor used for the background color of the action.

Int
@RequiresCarApi(value = 4)
getFlags()

Returns flags affecting how this action should be treated

CarIcon?

Returns the CarIcon to display in the action or null if the action does not have an icon.

OnClickDelegate?

Returns the OnClickDelegate that should be used for this action.

CarText?

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

Int

Returns the type of the action.

Int
Boolean
@RequiresCarApi(value = 5)
isEnabled()

Returns true if the action is enabled.

Boolean

Returns whether the action is a standard action such as BACK.

String
java-static String

Converts the given type into a string representation.

Constants

APP_ICON

Added in 1.0.0
const val APP_ICONAction

A standard action to show the app's icon.

This action is non-interactive.

BACK

Added in 1.0.0
const val BACKAction

A standard action to navigate back in the user interface.

The default behavior for a back press will call pop.

To override the default behavior, register a OnBackPressedCallback via addCallback, which you can retrieve from getOnBackPressedDispatcher.

COMPOSE_MESSAGE

Added in 1.4.0
@ExperimentalCarApi
@RequiresCarApi(value = 7)
const val COMPOSE_MESSAGEAction

A standard action to show the message compose button

This action is interactive.

FLAG_DEFAULT

Added in 1.3.0
@RequiresCarApi(value = 5)
const val FLAG_DEFAULT = 4: Int

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 Action is added for more details on any restriction(s) that might apply.

FLAG_IS_PERSISTENT

Added in 1.2.0
@RequiresCarApi(value = 5)
const val FLAG_IS_PERSISTENT = 2: Int

Indicates that this action will not fade in/out inside an ActionStrip.

FLAG_PRIMARY

Added in 1.1.0
@RequiresCarApi(value = 4)
const val FLAG_PRIMARY = 1: Int

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 Action is added for more details on any restriction(s) that might apply.

PAN

Added in 1.1.0
const val PANAction

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
const val TYPE_APP_ICON = 65538: Int

An action representing an app's icon.

See also
APP_ICON

TYPE_BACK

Added in 1.0.0
const val TYPE_BACK = 65539: Int

An action to navigate back in the user interface.

See also
BACK

TYPE_COMPOSE_MESSAGE

Added in 1.4.0
@ExperimentalCarApi
@RequiresCarApi(value = 7)
const val TYPE_COMPOSE_MESSAGE = 65541: Int

An action to allow user compose a message.

TYPE_CUSTOM

Added in 1.0.0
const val TYPE_CUSTOM = 1: Int

An app-defined custom action type.

TYPE_PAN

Added in 1.1.0
const val TYPE_PAN = 65540: Int

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

Public functions

equals

fun equals(other: Any?): Boolean

getBackgroundColor

Added in 1.0.0
fun getBackgroundColor(): CarColor?

Returns the CarColor used for the background color of the action.

getFlags

Added in 1.1.0
@RequiresCarApi(value = 4)
fun getFlags(): Int

Returns flags affecting how this action should be treated

getIcon

Added in 1.0.0
fun getIcon(): CarIcon?

Returns the CarIcon to display in the action or null if the action does not have an icon.

See also
setIcon

getOnClickDelegate

Added in 1.0.0
fun getOnClickDelegate(): OnClickDelegate?

Returns the OnClickDelegate that should be used for this action.

getTitle

Added in 1.0.0
fun getTitle(): CarText?

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

See also
setTitle

getType

Added in 1.0.0
fun getType(): Int

Returns the type of the action.

hashCode

fun hashCode(): Int

isEnabled

Added in 1.3.0
@RequiresCarApi(value = 5)
fun isEnabled(): Boolean

Returns true if the action is enabled.

isStandard

Added in 1.0.0
fun isStandard(): Boolean

Returns whether the action is a standard action such as BACK.

toString

fun toString(): String

typeToString

Added in 1.0.0
java-static fun typeToString(type: Int): String

Converts the given type into a string representation.