ActionBarDrawerToggle
open class ActionBarDrawerToggle : DrawerLayout.DrawerListener
kotlin.Any | |
↳ | 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 | |
---|---|
abstract | |
abstract |
Allows an implementing Activity to return an |
Public constructors | |
---|---|
<init>(activity: Activity!, drawerLayout: DrawerLayout!, @StringRes openDrawerContentDescRes: Int, @StringRes closeDrawerContentDescRes: Int) Construct a new ActionBarDrawerToggle. |
|
<init>(activity: Activity!, drawerLayout: DrawerLayout!, toolbar: Toolbar!, @StringRes openDrawerContentDescRes: Int, @StringRes closeDrawerContentDescRes: Int) Construct a new ActionBarDrawerToggle with a Toolbar. |
Public methods | |
---|---|
open DrawerArrowDrawable | |
open OnClickListener! |
Returns the fallback listener for Navigation icon click events. |
open Boolean | |
open Boolean | |
open Unit |
onConfigurationChanged(newConfig: Configuration!) This method should always be called by your |
open Unit |
onDrawerClosed(drawerView: View)
|
open Unit |
onDrawerOpened(drawerView: View)
|
open Unit |
onDrawerSlide(drawerView: View, slideOffset: Float)
|
open Unit |
onDrawerStateChanged(newState: Int)
|
open Boolean |
onOptionsItemSelected(item: MenuItem!) This method should be called by your |
open Unit |
setDrawerArrowDrawable(@NonNull drawable: DrawerArrowDrawable) Sets the DrawerArrowDrawable that should be shown by this ActionBarDrawerToggle. |
open Unit |
setDrawerIndicatorEnabled(enable: Boolean) Enable or disable the drawer indicator. |
open Unit |
setDrawerSlideAnimationEnabled(enabled: Boolean) Specifies whether the drawer arrow should animate when the drawer position changes. |
open Unit |
setHomeAsUpIndicator(indicator: Drawable!) Set the up indicator to display when the drawer indicator is not enabled. |
open Unit |
setHomeAsUpIndicator(resId: Int) Set the up indicator to display when the drawer indicator is not enabled. |
open Unit |
When DrawerToggle is constructed with a Toolbar, it sets the click listener on the Navigation icon. |
open Unit |
Synchronize the state of the drawer indicator/affordance with the linked DrawerLayout. |
Public constructors
<init>
ActionBarDrawerToggle(
activity: Activity!,
drawerLayout: DrawerLayout!,
@StringRes openDrawerContentDescRes: Int,
@StringRes closeDrawerContentDescRes: Int)
Construct a new ActionBarDrawerToggle.
The given Activity
will be linked to the specified DrawerLayout
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 |
Activity!: The Activity hosting the drawer. Should have an ActionBar. |
drawerLayout |
DrawerLayout!: The DrawerLayout to link to the given Activity's ActionBar |
openDrawerContentDescRes |
Int: A String resource to describe the "open drawer" action for accessibility |
closeDrawerContentDescRes |
Int: A String resource to describe the "close drawer" action for accessibility |
<init>
ActionBarDrawerToggle(
activity: Activity!,
drawerLayout: DrawerLayout!,
toolbar: Toolbar!,
@StringRes openDrawerContentDescRes: Int,
@StringRes closeDrawerContentDescRes: Int)
Construct a new ActionBarDrawerToggle with a Toolbar.
The given Activity
will be linked to the specified DrawerLayout
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 ActionBarDrawerToggle(Activity, DrawerLayout, int, int)
if you are setting the Toolbar as the ActionBar of your activity.
Parameters | |
---|---|
activity |
Activity!: The Activity hosting the drawer. |
toolbar |
Toolbar!: The toolbar to use if you have an independent Toolbar. |
drawerLayout |
DrawerLayout!: The DrawerLayout to link to the given Activity's ActionBar |
openDrawerContentDescRes |
Int: A String resource to describe the "open drawer" action for accessibility |
closeDrawerContentDescRes |
Int: A String resource to describe the "close drawer" action for accessibility |
Public methods
getDrawerArrowDrawable
@NonNull open fun getDrawerArrowDrawable(): DrawerArrowDrawable
Return | |
---|---|
DrawerArrowDrawable |
DrawerArrowDrawable that is currently shown by the ActionBarDrawerToggle. |
getToolbarNavigationClickListener
open fun getToolbarNavigationClickListener(): OnClickListener!
Returns the fallback listener for Navigation icon click events.
Return | |
---|---|
OnClickListener! |
The click listener which receives Navigation click events from Toolbar when drawer indicator is disabled. |
isDrawerIndicatorEnabled
open fun isDrawerIndicatorEnabled(): Boolean
Return | |
---|---|
Boolean |
true if the enhanced drawer indicator is enabled, false otherwise |
See Also
isDrawerSlideAnimationEnabled
open fun isDrawerSlideAnimationEnabled(): Boolean
Return | |
---|---|
Boolean |
whether the drawer slide animation is enabled |
onConfigurationChanged
open fun onConfigurationChanged(newConfig: Configuration!): Unit
This method should always be called by your Activity
's onConfigurationChanged
method.
Parameters | |
---|---|
newConfig |
Configuration!: The new configuration |
onDrawerClosed
open fun onDrawerClosed(drawerView: View): Unit
DrawerLayout.DrawerListener
callback method. If you do not use your ActionBarDrawerToggle instance directly as your DrawerLayout's listener, you should