public class

ActionDrawerToggle

extends Object
implements ActionDrawer.OnDrawerStateChangeListener ActionDrawer.OnDrawingListener
java.lang.Object
   ↳ com.droidux.ui.widgets.actiondrawer.ActionDrawerToggle

Class Overview

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

To use ActionDrawerToggle, 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.

ActionDrawerToggle can be used directly as a com.droidux.ui.widgets.actiondrawer.ActionDrawer.OnDrawingListener, 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 android.support.v7.appcompat.R.styleable#DrawerArrowToggle drawerArrowStyle in your ActionBar theme.

Summary

Nested Classes
interface ActionDrawerToggle.Delegate  
interface ActionDrawerToggle.DelegateProvider Allows an implementing Activity to return an ActionDrawerToggle.Delegate to use with ActionBarDrawerToggle. 
Public Constructors
ActionDrawerToggle(Activity activity, ActionDrawer actionDrawer, int openDrawerContentDescRes, int closeDrawerContentDescRes)
Construct a new ActionDrawerToggle.
ActionDrawerToggle(Activity activity, ActionDrawer actionDrawer, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes)
Construct a new ActionBarDrawerToggle with a appcompat-v7 Toolbar.
Public Methods
View.OnClickListener getToolbarNavigationClickListener()
Returns the fallback listener for Navigation icon click events.
boolean isDrawerIndicatorEnabled()
void onConfigurationChanged(Configuration newConfig)
This method should always be called by your Activity's onConfigurationChanged method.
void onDrawerStateChange(int oldState, int newState)
boolean onOptionsItemSelected(MenuItem item)
This method should be called by your Activity's onOptionsItemSelected method.
void setDrawerIndicatorEnabled(boolean enable)
Enable or disable the drawer indicator.
void setHomeAsUpIndicator(int resId)
Set the up indicator to display when the drawer indicator is not enabled.
void setHomeAsUpIndicator(Drawable indicator)
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 ActionDrawer.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.droidux.ui.widgets.actiondrawer.ActionDrawer.OnDrawerStateChangeListener
From interface com.droidux.ui.widgets.actiondrawer.ActionDrawer.OnDrawingListener

Public Constructors

public ActionDrawerToggle (Activity activity, ActionDrawer actionDrawer, int openDrawerContentDescRes, int closeDrawerContentDescRes)

Since: API Level 3.1

Construct a new ActionDrawerToggle.

The given Activity will be linked to the specified ActionDrawer and its Actionbar's Up button will be set to a custom drawable.

This drawable shows a Hamburger icon when drawer is closed and an arrow when drawer is open. It animates between these two states as the drawer opens.

String resources must be provided to describe the open/close drawer actions for accessibility services.

Parameters
activity The Activity hosting the drawer. Should have an ActionBar.
actionDrawer The ActionDrawer to link to the given Activity's ActionBar
openDrawerContentDescRes A String resource to describe the "open drawer" action for accessibility
closeDrawerContentDescRes A String resource to describe the "close drawer" action for accessibility

public ActionDrawerToggle (Activity activity, ActionDrawer actionDrawer, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes)

Since: API Level 3.1

Construct a new ActionBarDrawerToggle with a appcompat-v7 Toolbar.

The given Activity will be linked to the specified ActionDrawer and the Toolbar's navigation icon will be set to a custom drawable. Using this constructor will set Toolbar's navigation click listener to toggle the drawer when it is clicked.

This drawable shows a Hamburger icon when drawer is closed and an arrow when drawer is open. It animates between these two states as the drawer opens.

String resources must be provided to describe the open/close drawer actions for accessibility services.

Please use ActionDrawerToggle(android.app.Activity, ActionDrawer, int, int) if you are setting the Toolbar as the ActionBar of your activity.

Parameters
activity The Activity hosting the drawer.
actionDrawer The DrawerLayout to link to the given Activity's ActionBar
toolbar The toolbar to use if you have an independent appcompat-v7 Toolbar.
openDrawerContentDescRes A String resource to describe the "open drawer" action for accessibility
closeDrawerContentDescRes A String resource to describe the "close drawer" action for accessibility

Public Methods

public View.OnClickListener getToolbarNavigationClickListener ()

Since: API Level 3.1

Returns the fallback listener for Navigation icon click events.

Returns
  • The click listener which receives Navigation click events from Toolbar when drawer indicator is disabled.

public boolean isDrawerIndicatorEnabled ()

Since: API Level 3.0

Returns
  • true if the enhanced drawer indicator is enabled, false otherwise

public void onConfigurationChanged (Configuration newConfig)

Since: API Level 3.0

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

Parameters
newConfig The new configuration

public void onDrawerStateChange (int oldState, int newState)

Since: API Level 3.1

ActionDrawer.OnDrawerStateChangeListener callback method. If you do not use your ActionDrawerToggle instance directly as your ActionDrawer's OnDrawerStateChange listener, you should call through to this method from your own listener object.

public boolean onOptionsItemSelected (MenuItem item)

Since: API Level 3.0

This method should be called by your Activity's onOptionsItemSelected method. If it returns true, your onOptionsItemSelected method should return true and skip further processing.

Parameters
item the MenuItem instance representing the selected menu item
Returns
  • true if the event was handled and further processing should not occur

public void setDrawerIndicatorEnabled (boolean enable)

Since: API Level 3.0

Enable or disable the drawer indicator. The indicator defaults to enabled.

When the indicator is disabled, the ActionBar will revert to displaying the home-as-up indicator provided by the Activity's theme in the android.R.attr.homeAsUpIndicator attribute instead of the animated drawer glyph.

Parameters
enable true to enable, false to disable

public void setHomeAsUpIndicator (int resId)

Since: API Level 3.1

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

If you pass 0 to this method, the default drawable from the theme will be used.

Parameters
resId Resource ID of a drawable to use for the up indicator, or 0 to use the theme's default

public void setHomeAsUpIndicator (Drawable indicator)

Since: API Level 3.1

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

If you pass null to this method, the default drawable from the theme will be used.

Parameters
indicator A drawable to use for the up indicator, or null to use the theme's default

public void setToolbarNavigationClickListener (View.OnClickListener onToolbarNavigationClickListener)

Since: API Level 3.1

When DrawerToggle is constructed with a Toolbar, it sets the click listener on the Navigation icon. If you want to listen for clicks on the Navigation icon when DrawerToggle is disabled (setDrawerIndicatorEnabled(boolean), you should call this method with your listener and DrawerToggle will forward click events to that listener when drawer indicator is disabled.

public void syncState ()

Since: API Level 3.0

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

This should be called from your Activity's onPostCreate method to synchronize after the ActionDrawer's instance state has been restored, and any other time when the state may have diverged in such a way that the ActionDrawerToggle was not notified. (For example, if you stop forwarding appropriate drawer events for a period of time.)