Action.Builder
public final class Action.Builder
A builder of Action.
Summary
Public constructors |
|---|
Builder()Creates an empty |
@RequiresCarApi(value = 2)Returns a |
Public methods |
|
|---|---|
@NonNull Action |
build()Constructs the |
@NonNull Action.Builder |
setBackgroundColor(@NonNull CarColor backgroundColor)Sets the background color to be used for the action. |
@NonNull Action.Builder |
@RequiresCarApi(value = 5)Sets the initial enabled state for |
@NonNull Action.Builder |
@RequiresCarApi(value = 4)Sets flags affecting how this action should be treated. |
@NonNull Action.Builder |
Sets the icon to display in the action. |
@NonNull Action.Builder |
setOnClickListener(@NonNull OnClickListener listener)Sets the |
@NonNull Action.Builder |
Sets the title to display in the action, with support for multiple length variants. |
@NonNull Action.Builder |
setTitle(@NonNull CharSequence title)Sets the title to display in the action. |
Public constructors
Builder
@RequiresCarApi(value = 2)
public Builder(@NonNull Action action)
Returns a Builder instance configured with the same data as the given Action instance.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
Public methods
build
public @NonNull Action build()
Constructs the Action defined by this builder.
| Throws | |
|---|---|
java.lang.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 |
setBackgroundColor
public @NonNull Action.Builder setBackgroundColor(@NonNull CarColor backgroundColor)
Sets the background color to be used for the action.
RequirementsDepending 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 | |
|---|---|
@NonNull CarColor backgroundColor |
the |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setEnabled
@RequiresCarApi(value = 5)
public @NonNull Action.Builder setEnabled(boolean enabled)
Sets the initial enabled state for Action.
The default state of a Action is enabled.
setFlags
@RequiresCarApi(value = 4)
public @NonNull Action.Builder setFlags(int flags)
Sets flags affecting how this action should be treated.
setIcon
public @NonNull Action.Builder setIcon(@NonNull 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.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setOnClickListener
public @NonNull Action.Builder setOnClickListener(@NonNull 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 getMainLooper.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setTitle
public @NonNull Action.Builder setTitle(@NonNull CarText title)
Sets the title to display in the action, with support for multiple length variants.
Support for text spans depends on where the action is used. For example, most templates taking an action support ForegroundCarColorSpan, but this may vary. See the documentation of the specific APIs taking an Action for details.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
CarText |
setTitle
public @NonNull Action.Builder setTitle(@NonNull 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.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |