CarDrawerActivity

open class CarDrawerActivity
kotlin.Any
   ↳ androidx.car.drawer.CarDrawerActivity

Common base Activity for car apps that need to present a Drawer.

This Activity manages the overall layout. To use it, sub-classes need to:

This class will take care of drawer toggling and display.

This Activity also exposes the ability to have its toolbar optionally hide if any content in its main view is scrolled. Be default, this ability is turned off. Call #setToolbarCollapsible() to enable this behavior. Additionally, a user can set elevation on this toolbar by calling the appropriate #setToolbarElevation(float) method. There is elevation on the toolbar by default.

The rootAdapter can implement nested-navigation, in its click-handling, by passing the CarDrawerAdapter for the next level to CarDrawerController#pushAdapter(CarDrawerAdapter).

Any Activity's based on this class need to set their theme to Theme.Car.Light.NoActionBar.Drawer or a derivative.

Summary

Public constructors

Public methods
open Unit

Sets the elevation of the toolbar and animate it from the current elevation value.

open Unit

Sets whether clicks on the toolbar of this view will pass through to any views underneath it.

open Unit

Sets the toolbar of this Activity as collapsible.

open Unit

Set main content to display in this Activity.

open Unit
setMainContent(resourceId: Int)

Set main content to display in this Activity.

open Unit

open Boolean

open Unit

Sets the toolbar to always show even if content in the main view of the Activity has been scrolled.

open Unit

Sets the elevation on the toolbar of this Activity.

Protected methods
open Unit
onPostCreate(savedInstanceState: Bundle!)

open Unit

open Unit
onCreate(savedInstanceState: Bundle!)

open CarDrawerController?

Returns the CarDrawerController that is responsible for handling events relating to the drawer in this Activity.

open CarDrawerAdapter?

open Int

Get the id of the main content Container which is a FrameLayout.

Public constructors

<init>

CarDrawerActivity()

Public methods

setToolbarElevationWithAnimation

open fun setToolbarElevationWithAnimation(elevation: Float): Unit

Sets the elevation of the toolbar and animate it from the current elevation value.

Parameters
elevation Float: The elevation to set.

setToolbarClickThrough

open fun setToolbarClickThrough(clickThrough: Boolean): Unit

Sets whether clicks on the toolbar of this view will pass through to any views underneath it. By default, the toolbar will not allow clicks to pass through. This is the equivalent of passing false to this method.

Parameters
clickThrough Boolean: true if clicks will pass through; false for the toolbar to eat all clicks.

setToolbarCollapsible

open fun setToolbarCollapsible(): Unit

Sets the toolbar of this Activity as collapsible. When any content in the main view of the Activity is scrolled, the toolbar will collapse and show itself accordingly.

setMainContent

open fun setMainContent(view: View!): Unit

Set main content to display in this Activity. It will be added to R.id.content_frame in car_drawer_activity.xml. NOTE: Do not use #setContentView(View).

Parameters
view View!: View to display as main content.

setMainContent

open fun setMainContent(resourceId: Int): Unit

Set main content to display in this Activity. It will be added to R.id.content_frame in car_drawer_activity.xml. NOTE: Do not use #setContentView(int).

Parameters
resourceId Int: Layout to display as main content.

onConfigurationChanged

open fun onConfigurationChanged(newConfig: Configuration!): Unit

onOptionsItemSelected

open fun onOptionsItemSelected(item: MenuItem!): Boolean

setToolbarAlwaysShow

open fun setToolbarAlwaysShow(): Unit

Sets the toolbar to always show even if content in the main view of the Activity has been scrolled. This is the default behavior.

setToolbarElevation

open fun setToolbarElevation(elevation: Float): Unit

Sets the elevation on the toolbar of this Activity.

Parameters
elevation Float: The elevation to set.

Protected methods

onPostCreate

protected open fun onPostCreate(savedInstanceState: Bundle!): Unit

onStop

protected open fun onStop(): Unit

onCreate

protected open fun onCreate(savedInstanceState: Bundle!): Unit

getDrawerController

protected open fun getDrawerController(): CarDrawerController?

Returns the CarDrawerController that is responsible for handling events relating to the drawer in this Activity.

Return
CarDrawerController?: The CarDrawerController linked to this Activity. This value will be null if this method is called before onCreate() has been called.

getRootAdapter

protected open fun getRootAdapter(): CarDrawerAdapter?
Return
CarDrawerAdapter?: Adapter for root content of the Drawer.

getContentContainerId

protected open fun getContentContainerId(): Int

Get the id of the main content Container which is a FrameLayout. Subclasses can add their own content/fragments inside here.

Return
Int: Id of FrameLayout where main content of the subclass Activity can be added.