public class CarAction
- Object
- CarAction
A tappable action – a button shown in a CarActionStrip, a header action, or an action attached
to a CarPaneTemplate / CarMessageTemplate. Maps to androidx.car.app.model.Action and to a
CPBarButton / CPAlertAction on CarPlay. Use the fluent setters to configure it:
CarAction refresh = new CarAction("Refresh")
.setIcon(refreshIcon)
.setOnAction(ctx -> screen.invalidate());
Constructors
public CarAction() | Creates an empty action. |
public CarAction(String title) | Creates an action with the supplied title. |
Methods
public String getTitle() | Returns the action label, or null if icon-only. |
public CarAction setTitle(String title) | Sets the action label. |
public Image getIcon() | Returns the action icon, or null. |
public CarAction setIcon(Image icon) | Sets the action icon. |
public CarColor getBackgroundColor() | Returns the requested background colour role. |
public CarAction setBackgroundColor(CarColor backgroundColor) | Sets the background colour role (the head unit may ignore it for legibility). |
public CarActionListener getOnAction() | Returns the activation listener, or null. |
public CarAction setOnAction(CarActionListener listener) | Sets the listener invoked (on the EDT) when the action is selected. |
Inherited methods
Constructor details
CarAction
public CarAction()Creates an empty action. Set at least a title or an icon before use.
CarAction
public CarAction(String title)Creates an action with the supplied title.
Parameters
titleString- the action label
Method details
getTitle
public String getTitle()Returns the action label, or null if icon-only.
setTitle
public CarAction setTitle(String title)Sets the action label.
Parameters
titleString- the label
Returns
this action, for chaining
getIcon
public Image getIcon()Returns the action icon, or null.
setIcon
public CarAction setIcon(Image icon)Sets the action icon. The head unit renders it at a fixed size with its own tint.
Parameters
iconImage- the icon image
Returns
this action, for chaining
getBackgroundColor
public CarColor getBackgroundColor()Returns the requested background colour role.
setBackgroundColor
public CarAction setBackgroundColor(CarColor backgroundColor)Sets the background colour role (the head unit may ignore it for legibility).
Parameters
backgroundColorCarColor- the colour role
Returns
this action, for chaining
getOnAction
public CarActionListener getOnAction()Returns the activation listener, or null.
setOnAction
public CarAction setOnAction(CarActionListener listener)Sets the listener invoked (on the EDT) when the action is selected.
Parameters
listenerCarActionListener- the activation callback
Returns
this action, for chaining