Action.Builder

public static final class Action.Builder
extends Object

java.lang.Object
   ↳ androidx.car.app.model.Action.Builder


A builder of Action.

Summary

Public constructors

Builder()

Creates an empty Action.Builder instance.

Builder(Action action)

Returns a Action.Builder instance configured with the same data as the given Action instance.

Public methods

Action build()

Constructs the Action defined by this builder.

Action.Builder setBackgroundColor(CarColor backgroundColor)

Sets the background color to be used for the action.

Action.Builder setIcon(CarIcon icon)

Sets the icon to display in the action.

Action.Builder setOnClickListener(OnClickListener listener)

Sets the OnClickListener to call when the action is clicked.

Action.Builder setTitle(CharSequence title)

Sets the title to display in the action.

Action.Builder setTitle(CarText title)

Sets the title to display in the action, with support for multiple length variants.

Inherited methods

Public constructors

Builder

public Builder ()

Creates an empty Action.Builder instance.

Builder

public Builder (Action action)

Returns a Action.Builder instance configured with the same data as the given Action instance.

Parameters
action Action

Throws
NullPointerException if action is null

Public methods

build

public Action build ()

Constructs the Action defined by this builder.

Returns
Action

Throws
IllegalStateException if the action is not a standard action and does not have an icon or a title, if a listener is set on either Action.APP_ICON or Action.BACK, or if an icon or title is set on either Action.APP_ICON or Action.BACK

setBackgroundColor

public Action.Builder setBackgroundColor (CarColor backgroundColor)

Sets the background color to be used for the action.

Requirements

Depending on contrast requirements, capabilities of the vehicle screens, or other factors, the color may be ignored by the host or overridden by the vehicle system. See the documentation on where the Action is added for more details on any other restriction(s) that might apply.

Parameters
backgroundColor CarColor: the CarColor to set as background. Use CarColor.DEFAULT to let the host pick a default

Returns
Action.Builder

Throws
NullPointerException if backgroundColor is null

setIcon

public Action.Builder setIcon (CarIcon icon)

Sets the icon to display in the action.

Unless set with this method, the action will not have an icon.

Icon Sizing Guidance

To minimize scaling artifacts across a wide range of car screens, apps should provide icons targeting a 88 x 88 dp bounding box. If the icon exceeds this maximum size in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving its aspect ratio.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Parameters
icon CarIcon

Returns
Action.Builder

Throws
NullPointerException if icon is null

setOnClickListener

public Action.Builder setOnClickListener (OnClickListener listener)

Sets the OnClickListener to call when the action is clicked.

Unless set with this method, the action will not have a click listener.

Note that the listener relates to UI events and will be executed on the main thread using Looper.getMainLooper().

Parameters
listener OnClickListener

Returns
Action.Builder

Throws
NullPointerException if listener is null

setTitle

public Action.Builder setTitle (CharSequence title)

Sets the title to display in the action.

Support for text spans depends on where the action is used. See the documentation of the specific APIs taking an Action for details.

Parameters
title CharSequence

Returns
Action.Builder

Throws
NullPointerException if title is null

setTitle

public Action.Builder setTitle (CarText title)