Register now for Android Dev Summit 2019!

CarMenuItem

open class CarMenuItem
kotlin.Any
   ↳ 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 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

Builder for creating a CarMenuItem

Display behaviors for CarMenuItems.

abstract

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

Public methods

open CarMenuItem.DisplayBehavior

Returns The DisplayBehavior of the CarMenuItem.

open Icon?

Returns the icon of the CarMenuItem.

open CarMenuItem.OnClickListener?

Returns the OnClickListener of the CarMenuItem.

open Int

Returns the Res Id of the CarMenuItem's style.

open CharSequence?

Returns the title of the CarMenuItem.

open Boolean

Returns true if the CarMenuItem is checkable.

open Boolean

Returns true if the CarMenuItem is checked.

open Boolean

Returns true if the CarMenuItem is enabled.

open Unit
setChecked(checked: Boolean)

Sets whether the CarMenuItem is checked or not.

open Unit
setEnabled(enabled: Boolean)

Sets whether the CarMenuItem is enabled or disabled.

open Unit
setTitle(@Nullable title: CharSequence?)

Sets the title of the CarMenuItem.

Public methods

getDisplayBehavior

@NonNull open fun getDisplayBehavior(): CarMenuItem.DisplayBehavior

Returns The DisplayBehavior of the CarMenuItem.

getIcon

@Nullable open fun getIcon(): Icon?

Returns the icon of the CarMenuItem.

getOnClickListener

@Nullable open fun getOnClickListener(): CarMenuItem.OnClickListener?

Returns the OnClickListener of the CarMenuItem.

getStyleResId

@StyleRes open fun getStyleResId(): Int

Returns the Res Id of the CarMenuItem's style.

getTitle

@Nullable open fun getTitle(): CharSequence?

Returns the title of the CarMenuItem.

isCheckable

open fun isCheckable(): Boolean

Returns true if the CarMenuItem is checkable.

isChecked

open fun isChecked(): Boolean

Returns true if the CarMenuItem is checked.

isEnabled

open fun isEnabled(): Boolean

Returns true if the CarMenuItem is enabled.

setChecked

open fun setChecked(checked: Boolean): Unit

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

Parameters
checked Boolean: true if the CarMenuItem is checked.

setEnabled

open fun setEnabled(enabled: Boolean): Unit

Sets whether the CarMenuItem is enabled or disabled.

Items are enabled by default.

Parameters
enabled Boolean: true if the CarMenuItem is enabled.

setTitle

open fun setTitle(@Nullable title: CharSequence?): Unit

Sets the title of the CarMenuItem.

Parameters
title CharSequence?: Title of the CarMenuItem.