Action
@CarProtocol
public final 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.
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 |
|---|
public final class Action.BuilderA builder of |
Constants |
|
|---|---|
static final @NonNull Action |
A standard action to show the app's icon. |
static final @NonNull Action |
A standard action to navigate back in the user interface. |
static final @NonNull Action |
@ExperimentalCarApiA standard action to show the message compose button |
static final int |
@RequiresCarApi(value = 5)Indicates that this action is the default action out of a set of other actions. |
static final int |
@RequiresCarApi(value = 5)Indicates that this action will not fade in/out inside an |
static final int |
@RequiresCarApi(value = 4)Indicates that this action is the most important one, out of a set of other actions. |
static final @NonNull Action |
@ExperimentalCarApiA standard action to show the media playback button. |
static final @NonNull Action |
A standard action to toggle the pan mode in a map-based template. |
static final int |
TYPE_APP_ICON = 65538An action representing an app's icon. |
static final int |
TYPE_BACK = 65539An action to navigate back in the user interface. |
static final int |
@ExperimentalCarApiAn action to allow user compose a message. |
static final int |
TYPE_CUSTOM = 1An app-defined custom action type. |
static final int |
@ExperimentalCarApiA standard action to show the media playback button. |
static final int |
TYPE_PAN = 65540An action to toggle the pan mode in a map-based template. |
Public methods |
|
|---|---|
boolean |
|
@Nullable CarColor |
Returns the |
int |
@RequiresCarApi(value = 4)Returns flags affecting how this action should be treated |
@Nullable CarIcon |
getIcon()Returns the |
@Nullable OnClickDelegate |
Returns the |
@Nullable CarText |
getTitle()Returns the title displayed in the action or |
int |
getType()Returns the type of the action. |
int |
hashCode() |
boolean |
@RequiresCarApi(value = 5)Returns |
boolean |
Returns whether the action is a standard action such as |
@NonNull String |
toString() |
static @NonNull String |
typeToString(int type)Converts the given |
Constants
APP_ICON
public static final @NonNull Action APP_ICON
A standard action to show the app's icon.
This action is non-interactive.
BACK
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 pop.
To override the default behavior, register a OnBackPressedCallback via addCallback, which you can retrieve from getOnBackPressedDispatcher.
COMPOSE_MESSAGE
@ExperimentalCarApi
@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
@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 Action is added for more details on any restriction(s) that might apply.
FLAG_IS_PERSISTENT
@RequiresCarApi(value = 5)
public static final int FLAG_IS_PERSISTENT = 2
Indicates that this action will not fade in/out inside an ActionStrip.
FLAG_PRIMARY
@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 Action is added for more details on any restriction(s) that might apply.
MEDIA_PLAYBACK
@ExperimentalCarApi
@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 androidx.car.app.MEDIA_TEMPLATES can use this action. There are 2 ways to use this action.
- Used as a floating action button in a browse view, the action must provide an
OnClickListenerwhich pushes aScreenthat provides aMediaPlaybackTemplate. - Used as a
mActionsto indicate the currently playing song. An optionalOnClickListenercan be added.
PAN
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
public static final int TYPE_APP_ICON = 65538
An action representing an app's icon.
| See also | |
|---|---|
APP_ICON |
TYPE_BACK
public static final int TYPE_BACK = 65539
An action to navigate back in the user interface.
| See also | |
|---|---|
BACK |
TYPE_COMPOSE_MESSAGE
@ExperimentalCarApi
@RequiresCarApi(value = 7)
public static final int TYPE_COMPOSE_MESSAGE = 65541
An action to allow user compose a message.
TYPE_CUSTOM
public static final int TYPE_CUSTOM = 1
An app-defined custom action type.
TYPE_MEDIA_PLAYBACK
@ExperimentalCarApi
@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 androidx.car.app.MEDIA_TEMPLATES can use this action. There are 2 ways to use this action.
- Used as a floating action button in a browse view, the action must provide an
OnClickListenerwhich pushes aScreenthat provides aMediaPlaybackTemplate. - Used as a
mActionsto indicate the currently playing song. An optionalOnClickListenercan be added.
Public methods
getBackgroundColor
public @Nullable CarColor getBackgroundColor()
Returns the CarColor used for the background color of the action.
| See also | |
|---|---|
setBackgroundColor |
getFlags
@RequiresCarApi(value = 4)
public int getFlags()
Returns flags affecting how this action should be treated
getIcon
public @Nullable CarIcon getIcon()
Returns the CarIcon to display in the action or null if the action does not have an icon.
| See also | |
|---|---|
setIcon |
getOnClickDelegate
public @Nullable OnClickDelegate getOnClickDelegate()
Returns the OnClickDelegate that should be used for this action.
getTitle
public @Nullable CarText getTitle()
Returns the title displayed in the action or null if the action does not have a title.
| See also | |
|---|---|
setTitle |
isEnabled
@RequiresCarApi(value = 5)
public boolean isEnabled()
Returns true if the action is enabled.
isStandard
public boolean isStandard()
Returns whether the action is a standard action such as BACK.
typeToString
public static @NonNull String typeToString(int type)
Converts the given type into a string representation.