belongs to Maven artifact androidx.car:car:1.0.0-alpha1

CarDrawerActivity

public class CarDrawerActivity
extends AppCompatActivity

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ androidx.fragment.app.FragmentActivity
             ↳ androidx.appcompat.app.AppCompatActivity
               ↳ 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

Inherited constants

Inherited fields

Public constructors

CarDrawerActivity()

Public methods

void onConfigurationChanged(Configuration newConfig)

Dispatch configuration change to all fragments.

boolean onOptionsItemSelected(MenuItem item)
void setMainContent(int resourceId)

Set main content to display in this Activity.

void setMainContent(View view)

Set main content to display in this Activity.

void setToolbarAlwaysShow()

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

void setToolbarClickThrough(boolean clickThrough)

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

void setToolbarCollapsible()

Sets the toolbar of this Activity as collapsible.

void setToolbarElevation(float elevation)

Sets the elevation on the toolbar of this Activity.

void setToolbarElevationWithAnimation(float elevation)

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

Protected methods

int getContentContainerId()

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

CarDrawerController getDrawerController()

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

CarDrawerAdapter getRootAdapter()

This method is deprecated. Do not implement this, instead call getDrawerController(). CarDrawerController.setRootAdapter(CarDrawerAdapter) directly.

void onCreate(Bundle savedInstanceState)

Perform initialization of all fragments.

void onPostCreate(Bundle savedInstanceState)
void onStop()

Dispatch onStop() to all fragments.

Inherited methods

Public constructors

CarDrawerActivity

CarDrawerActivity ()

Public methods

onConfigurationChanged

void onConfigurationChanged (Configuration newConfig)

Dispatch configuration change to all fragments.

Parameters
newConfig Configuration

onOptionsItemSelected

boolean onOptionsItemSelected (MenuItem item)

Parameters
item MenuItem

Returns
boolean

setMainContent

void setMainContent (int resourceId)

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 AppCompatActivity.setContentView(int).

Parameters
resourceId int: Layout to display as main content.

setMainContent

void setMainContent (View view)

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 AppCompatActivity.setContentView(View).

Parameters
view View: View to display as main content.

setToolbarAlwaysShow

void setToolbarAlwaysShow ()

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

setToolbarClickThrough

void setToolbarClickThrough (boolean clickThrough)

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

void setToolbarCollapsible ()

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.

setToolbarElevation

void setToolbarElevation (float elevation)

Sets the elevation on the toolbar of this Activity.

Parameters
elevation float: The elevation to set.

setToolbarElevationWithAnimation

void setToolbarElevationWithAnimation (float elevation)

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

Parameters
elevation float: The elevation to set.

Protected methods

getContentContainerId

int getContentContainerId ()

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

Returns
int Id of FrameLayout where main content of the subclass Activity can be added.

getDrawerController

CarDrawerController getDrawerController ()

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

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

getRootAdapter

CarDrawerAdapter getRootAdapter ()

This method is deprecated.
Do not implement this, instead call getDrawerController(). CarDrawerController.setRootAdapter(CarDrawerAdapter) directly.

Returns
CarDrawerAdapter Adapter for root content of the Drawer.

onCreate

void onCreate (Bundle savedInstanceState)

Perform initialization of all fragments.

Parameters
savedInstanceState Bundle

onPostCreate

void onPostCreate (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onStop

void onStop ()

Dispatch onStop() to all fragments.