Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

CarMenuItem

public class CarMenuItem
extends Object

java.lang.Object
   ↳ androidx.car.widget.CarMenuItem


Class to build a CarMenuItem that appears in the CarToolbar menu.

The following properties can be specified:

  • Title - Primary text that is shown on the item.
  • CarMenuItem.OnClickListener - Listener that handles the clicks on the item.
  • Icon - An Icon shown before the title, if the item is not checkable (a switch).
  • Style - A Resource Id that specifies the style of the item if it's not an overflow item.
  • Enabled - A boolean that specifies whether the item is enabled or disabled.
  • Checkable - A boolean that specifies whether the item is checkable (a switch) or not.
  • Checked - A boolean that specifies whether the item is currently checked or not.
  • DisplayBehavior - A CarMenuItem.DisplayBehavior that specifies where the item is displayed.

Properties such as the title, isEnabled, and isChecked can be modified after creation, and as such, have setters in the class and the builder.

Summary

Nested classes

class CarMenuItem.Builder

Builder for creating a CarMenuItem  

enum CarMenuItem.DisplayBehavior

Display behaviors for CarMenuItems. 

interface CarMenuItem.OnClickListener

Interface definition for a callback to be invoked when a CarMenuItem is clicked. 

Public methods

CarMenuItem.DisplayBehavior getDisplayBehavior()

Returns The CarMenuItem.DisplayBehavior of the CarMenuItem.

Icon getIcon()

Returns the icon of the CarMenuItem.

CarMenuItem.OnClickListener getOnClickListener()

Returns the CarMenuItem.OnClickListener of the CarMenuItem.

int getStyleResId()

Returns the Res Id of the CarMenuItem's style.

CharSequence getTitle()

Returns the title of the CarMenuItem.

boolean isCheckable()

Returns true if the CarMenuItem is checkable.

boolean isChecked()

Returns true if the CarMenuItem is checked.

boolean isEnabled()

Returns true if the CarMenuItem is enabled.

void setChecked(boolean checked)

Sets whether the CarMenuItem is checked or not.

void setEnabled(boolean enabled)

Sets whether the CarMenuItem is enabled or disabled.

void setTitle(CharSequence title)

Sets the title of the CarMenuItem.

Inherited methods

Public methods

getDisplayBehavior

public CarMenuItem.DisplayBehavior getDisplayBehavior ()

Returns The CarMenuItem.DisplayBehavior of the CarMenuItem.

Returns
CarMenuItem.DisplayBehavior

getIcon

public Icon getIcon ()

Returns the icon of the CarMenuItem.

Returns
Icon

getOnClickListener

public CarMenuItem.OnClickListener getOnClickListener ()

Returns the CarMenuItem.OnClickListener of the CarMenuItem.

Returns
CarMenuItem.OnClickListener

getStyleResId

public int getStyleResId ()

Returns the Res Id of the CarMenuItem's style.

Returns
int

getTitle

public CharSequence getTitle ()

Returns the title of the CarMenuItem.

Returns
CharSequence

isCheckable

public boolean isCheckable ()

Returns true if the CarMenuItem is checkable.

Returns
boolean

isChecked

public boolean isChecked ()

Returns true if the CarMenuItem is checked.

Returns
boolean

isEnabled

public boolean isEnabled ()

Returns true if the CarMenuItem is enabled.

Returns
boolean

setChecked

public void setChecked (boolean checked)

Sets whether the CarMenuItem is checked or not. This method will only have an effect if this CarMenuItem was built with CarMenuItem.Builder.setCheckable(boolean) set to true.

Parameters
checked boolean: true if the CarMenuItem is checked.

setEnabled

public void setEnabled (boolean enabled)

Sets whether the CarMenuItem is enabled or disabled.

Items are enabled by default.

Parameters
enabled boolean: true if the CarMenuItem is enabled.

setTitle

public void setTitle (CharSequence title)

Sets the title of the CarMenuItem.

Parameters
title CharSequence: Title of the CarMenuItem.