ActionBarDrawerToggle

public class ActionBarDrawerToggle
extends Object implements DrawerLayout.DrawerListener

java.lang.Object
   ↳ androidx.appcompat.app.ActionBarDrawerToggle


This class provides a handy way to tie together the functionality of DrawerLayout and the framework ActionBar to implement the recommended design for navigation drawers.

To use ActionBarDrawerToggle, create one in your Activity and call through to the following methods corresponding to your Activity callbacks:

Call syncState() from your Activity's onPostCreate to synchronize the indicator with the state of the linked DrawerLayout after onRestoreInstanceState has occurred.

ActionBarDrawerToggle can be used directly as a DrawerLayout.DrawerListener, or if you are already providing your own listener, call through to each of the listener methods from your own.

You can customize the the animated toggle by defining the drawerArrowStyle in your ActionBar theme.

Summary

Nested classes

interface ActionBarDrawerToggle.Delegate

 

interface ActionBarDrawerToggle.DelegateProvider

Allows an implementing Activity to return an ActionBarDrawerToggle.Delegate to use with ActionBarDrawerToggle. 

Public constructors

ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int openDrawerContentDescRes, int closeDrawerContentDescRes)

Construct a new ActionBarDrawerToggle.

ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes)

Construct a new ActionBarDrawerToggle with a Toolbar.

Public methods

DrawerArrowDrawable getDrawerArrowDrawable()
View.OnClickListener getToolbarNavigationClickListener()

Returns the fallback listener for Navigation icon click events.

boolean isDrawerIndicatorEnabled()
boolean isDrawerSlideAnimationEnabled()
void onConfigurationChanged(Configuration newConfig)

This method should always be called by your Activity's onConfigurationChanged method.

void onDrawerClosed(View drawerView)

DrawerLayout.DrawerListener callback method.

void onDrawerOpened(View drawerView)

DrawerLayout.DrawerListener callback method.

void onDrawerSlide(View drawerView, float slideOffset)

DrawerLayout.DrawerListener callback method.

void onDrawerStateChanged(int newState)

DrawerLayout.DrawerListener callback method.

boolean onOptionsItemSelected(MenuItem item)

This method should be called by your Activity's onOptionsItemSelected method.

void setDrawerArrowDrawable(DrawerArrowDrawable drawable)

Sets the DrawerArrowDrawable that should be shown by this ActionBarDrawerToggle.

void setDrawerIndicatorEnabled(boolean enable)

Enable or disable the drawer indicator.

void setDrawerSlideAnimationEnabled(boolean enabled)

Specifies whether the drawer arrow should animate when the drawer position changes.

void setHomeAsUpIndicator(Drawable indicator)

Set the up indicator to display when the drawer indicator is not enabled.

void setHomeAsUpIndicator(int resId)

Set the up indicator to display when the drawer indicator is not enabled.

void setToolbarNavigationClickListener(View.OnClickListener onToolbarNavigationClickListener)

When DrawerToggle is constructed with a Toolbar, it sets the click listener on the Navigation icon.

void syncState()

Synchronize the state of the drawer indicator/affordance with the linked DrawerLayout.

Inherited methods