The Android Developer Challenge is back! Submit your idea before December 2.

CarToolbar

open class CarToolbar : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.car.widget.CarToolbar

A toolbar for building car applications.

CarToolbar provides a subset of features of Toolbar through a driving safe UI. From start to end, a CarToolbar provides the following elements:

  • A navigation button. Similar to that in Toolbar, navigation button should always provide access to other navigational destinations. If navigation button is to be used as Up Button, its OnClickListener needs to explicitly invoke AppCompatActivity#onSupportNavigateUp()
  • A title icon. A @Drawable shown before the title.
  • A title. A single line primary text that ellipsizes at the end.
  • A subtitle. A single line secondary text that ellipsizes at the end.
  • An overflow button. A button that opens the overflow menu.

CarMenuItem in overflow menu will be shown as a CarListDialog. Overflow menu items with icons are not supported yet, i.e. only texts from CarMenuItem#getTitle() will be displayed.

One distinction between CarToolbar and Toolbar is that CarToolbar cannot be used as action bar through androidx.appcompat.app.AppCompatActivity#setSupportActionBar(Toolbar).

The CarToolbar has a fixed height of R.dimen.car_app_bar_height.

Summary

Public constructors

<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods

open LayoutParams!

open MutableList<CarMenuItem!>?

Returns a list of this CarToolbar's CarMenuItems, or null if none were set.

open CharSequence?

Returns the subtitle of this toolbar.

open CharSequence!

Returns the title of this toolbar.

open Unit

Hides the overflow menu.

open Boolean

Returns true if the overflow menu is showing.

open Unit
setMenuItems(@Nullable items: MutableList<CarMenuItem!>?)

Sets the list of CarMenuItems that will be displayed on this CarToolbar.

open Unit
setNavigationIcon(@DrawableRes iconResId: Int)

Set the icon to use for the toolbar's navigation button.

open Unit
setNavigationIcon(@Nullable icon: Drawable?)

Set the icon to use for the toolbar's navigation button.

open Unit

Sets the width of container for navigation icon.

open Unit

Sets a listener to respond to navigation events.

open Unit

Sets the tint color for the navigation icon.

open Unit
setNavigationIconTint(@Nullable colorFilter: ColorFilter?)

Sets the given ColorFilter as the tint for the navigation icon.

open Unit
setOverflowIcon(@DrawableRes iconResId: Int)

Sets the icon of the overflow menu button.

open Unit
setOverflowIcon(@NonNull icon: Drawable)

Sets the icon of the overflow menu button.

open Unit
setSubtitle(@StringRes resId: Int)

Sets the subtitle of this toolbar.

open Unit
setSubtitle(@Nullable subtitle: CharSequence?)

Sets the subtitle of this toolbar.

open Unit
setSubtitleTextAppearance(@StyleRes resId: Int)

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

open Unit
setTitle(@StringRes resId: Int)

Sets the title of this toolbar.

open Unit

Sets the title of this toolbar.

open Unit
setTitleIcon(@DrawableRes iconResId: Int)

Sets the title icon to use in the toolbar.

open Unit
setTitleIcon(@Nullable icon: Drawable?)

Sets the title icon to use in the toolbar.

open Unit

Sets the end margin of the title icon.

open Unit
setTitleIconSize(@Px size: Int)

Sets a new size for the title icon.

open Unit

Sets the start margin of the title icon.

open Unit
setTitleTextAppearance(@StyleRes resId: Int)

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

open Unit

Shows the overflow menu.

Protected methods

open Boolean

open LayoutParams!

open LayoutParams!

open Int

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Public constructors

<init>

CarToolbar(context: Context!)

<init>

CarToolbar(context: Context!, attrs: AttributeSet!)

<init>

CarToolbar(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>

CarToolbar(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods

generateLayoutParams

open fun generateLayoutParams(attrs: AttributeSet!): LayoutParams!

getMenuItems

@Nullable open fun getMenuItems(): MutableList<CarMenuItem!>?

Returns a list of this CarToolbar's CarMenuItems, or null if none were set.

getSubtitle

@Nullable open fun getSubtitle(): CharSequence?

Returns the subtitle of this toolbar.

Return
CharSequence?: The current subtitle, or null if none has been set.

getTitle

open fun getTitle(): CharSequence!

Returns the title of this toolbar.

Return
CharSequence!: The current title.

hideOverflowMenu

open fun hideOverflowMenu(): Unit

Hides the overflow menu.

isOverflowMenuShowing

open fun isOverflowMenuShowing(): Boolean

Returns true if the overflow menu is showing.

setMenuItems

open fun setMenuItems(@Nullable items: MutableList<CarMenuItem!>?): Unit

Sets the list of CarMenuItems that will be displayed on this CarToolbar.

Parameters
items MutableList<CarMenuItem!>?: List of CarMenuItems to display, null to remove all items.

setNavigationIcon

open fun setNavigationIcon(@DrawableRes iconResId: Int): Unit

Set the icon to use for the toolbar's navigation button.

The navigation button appears at the start of the toolbar if present. Setting an icon will make the navigation button visible.

Parameters
iconResId Int: The resource id of the icon to set on the navigatino button. R.attr#navigationIcon

setNavigationIcon

open fun setNavigationIcon(@Nullable icon: Drawable?): Unit

Set the icon to use for the toolbar's navigation button.

The navigation button appears at the start of the toolbar if present. Setting an icon will make the navigation button visible.

Parameters
icon Drawable?: Icon to set; null will hide the icon. R.attr#navigationIcon

setNavigationIconContainerWidth

open fun setNavigationIconContainerWidth(@Px width: Int): Unit

Sets the width of container for navigation icon.

Navigation icon will be horizontally centered in its container. If the width of container is less than that of navigation icon, there will be no space on both ends of navigation icon.

Parameters
width Int: Width of container in pixels.

setNavigationIconOnClickListener

open fun setNavigationIconOnClickListener(@Nullable listener: OnClickListener?): Unit

Sets a listener to respond to navigation events.

This listener will be called whenever the user clicks the navigation button at the start of the toolbar. An icon must be set for the navigation button to appear.

Parameters
listener OnClickListener?: Listener to set.

setNavigationIconTint

open fun setNavigationIconTint(tint: Int): Unit

Sets the tint color for the navigation icon.

Parameters
tint Int: Color tint to apply. R.attr#navigationIconTint

setNavigationIconTint

open fun setNavigationIconTint(@Nullable colorFilter: ColorFilter?): Unit

Sets the given ColorFilter as the tint for the navigation icon. A null ColorFilter will clear any set color filters.

Parameters
colorFilter ColorFilter?: Color filter to apply for the tint. R.attr#navigationIconTint

setOverflowIcon

open fun setOverflowIcon(@DrawableRes iconResId: Int): Unit

Sets the icon of the overflow menu button.

Parameters
iconResId Int: Resource id of the drawable to use for the overflow menu button. R.attr#overflowIcon

setOverflowIcon

open fun setOverflowIcon(@NonNull icon: Drawable): Unit

Sets the icon of the overflow menu button.

Parameters
icon Drawable: Icon to set. R.attr#overflowIcon

setSubtitle

open fun setSubtitle(@StringRes resId: Int): Unit

Sets the subtitle of this toolbar.

Subtitles should express extended information about the current content. Subtitle will appear underneath the title if the title exists.

Parameters
resId Int: Resource ID of a string to set as the subtitle.

setSubtitle

open fun setSubtitle(@Nullable subtitle: CharSequence?): Unit

Sets the subtitle of this toolbar.

Subtitle should express extended information about the current content. Subtitle will appear underneath the title if the title exists.

Parameters
subtitle CharSequence?: Subtitle to set. null or empty string will hide the subtitle.

setSubtitleTextAppearance

open fun setSubtitleTextAppearance(@StyleRes resId: Int): Unit

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

Parameters
resId Int: Resource id of TextAppearance.

setTitle

open fun setTitle(@StringRes resId: Int): Unit

Sets the title of this toolbar.

A title should be used as the anchor for a section of content. It should describe or name the content being viewed.

Parameters
resId Int: Resource ID of a string to set as the title.

setTitle

open fun setTitle(title: CharSequence!): Unit

Sets the title of this toolbar.

A title should be used as the anchor for a section of content. It should describe or name the content being viewed.

null or empty string will hide the title.

Parameters
title CharSequence!: Title to set.

setTitleIcon

open fun setTitleIcon(@DrawableRes iconResId: Int): Unit

Sets the title icon to use in the toolbar.

The title icon is positioned between the navigation button and the title.

Parameters
iconResId Int: Resource id of the drawable to use as the title icon. R.attr#titleIcon

setTitleIcon

open fun setTitleIcon(@Nullable icon: Drawable?): Unit

Sets the title icon to use in the toolbar.

The title icon is positioned between the navigation button and the title.

Parameters
icon Drawable?: Icon to set; null will hide the icon. R.attr#titleIcon

setTitleIconEndMargin

open fun setTitleIconEndMargin(@Px margin: Int): Unit

Sets the end margin of the title icon.

Parameters
margin Int: End margin of the title icon in pixels. R.attr#titleIconEndMargin

setTitleIconSize

open fun setTitleIconSize(@Px size: Int): Unit

Sets a new size for the title icon.

Parameters
size Int: Size of the title icon dimensions in pixels. R.attr#titleIconSize

setTitleIconStartMargin

open fun setTitleIconStartMargin(@Px margin: Int): Unit

Sets the start margin of the title icon.

Parameters
margin Int: Start margin of the title icon in pixels. R.attr#titleIconStartMargin

setTitleTextAppearance

open fun setTitleTextAppearance(@StyleRes resId: Int): Unit

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

Parameters
resId Int: Resource id of TextAppearance.

showOverflowMenu

open fun showOverflowMenu(): Unit

Shows the overflow menu.

Protected methods

checkLayoutParams

protected open fun checkLayoutParams(p: LayoutParams!): Boolean

generateDefaultLayoutParams

protected open fun generateDefaultLayoutParams(): LayoutParams!

generateLayoutParams

protected open fun generateLayoutParams(p: LayoutParams!): LayoutParams!

getSuggestedMinimumHeight

protected open fun getSuggestedMinimumHeight(): Int

onLayout

protected open fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int): Unit

onMeasure

protected open fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit