Class CarAction

java.lang.Object
com.codename1.car.CarAction

public class CarAction extends Object

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());
  • 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
      • title: 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
      • title: 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
      • icon: 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
      • backgroundColor: 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
      • listener: the activation callback
      Returns

      this action, for chaining