belongs to Maven artifact com.android.support:support-core-ui:28.0.0-alpha1
Deprecated since version 22.1.0
ActionBarDrawerToggle
public
class
ActionBarDrawerToggle
extends Object
implements
DrawerLayout.DrawerListener
java.lang.Object | |
↳ | android.support.v4.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.
Summary
Nested classes | |
---|---|
interface |
ActionBarDrawerToggle.Delegate
This interface was deprecated in API level 25.4.0. Use ActionBarDrawerToggle.DelegateProvider in support-v7-appcompat. |
interface |
ActionBarDrawerToggle.DelegateProvider
This interface was deprecated in API level 25.4.0. Use ActionBarDrawerToggle.DelegateProvider in support-v7-appcompat. |
Public constructors | |
---|---|
ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes)
Construct a new ActionBarDrawerToggle. |
|
ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, boolean animate, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes)
Construct a new ActionBarDrawerToggle. |
Public methods | |
---|---|
boolean
|
isDrawerIndicatorEnabled()
|
void
|
onConfigurationChanged(Configuration newConfig)
This method should always be called by your |
void
|
onDrawerClosed(View drawerView)
|
void
|
onDrawerOpened(View drawerView)
|
void
|
onDrawerSlide(View drawerView, float slideOffset)
|
void
|
onDrawerStateChanged(int newState)
|
boolean
|
onOptionsItemSelected(MenuItem item)
This method should be called by your |
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
|
syncState()
Synchronize the state of the drawer indicator/affordance with the linked DrawerLayout. |
Inherited methods | |
---|---|
From
class
java.lang.Object
| |
From
interface
android.support.v4.widget.DrawerLayout.DrawerListener
|
Public constructors
ActionBarDrawerToggle
ActionBarDrawerToggle (Activity activity, DrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes)
Construct a new ActionBarDrawerToggle.
The given Activity
will be linked to the specified DrawerLayout
.
The provided drawer indicator drawable will animate slightly off-screen as the drawer
is opened, indicating that in the open state the drawer will move off-screen when pressed
and in the closed state the drawer will move on-screen when pressed.
String resources must be provided to describe the open/close drawer actions for accessibility services.
Parameters | |
---|---|
activity |
Activity : The Activity hosting the drawer |
drawerLayout |
DrawerLayout : The DrawerLayout to link to the given Activity's ActionBar |
drawerImageRes |
int : A Drawable resource to use as the drawer indicator |
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
|
ActionBarDrawerToggle
ActionBarDrawerToggle (Activity activity, DrawerLayout drawerLayout, boolean animate, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes)
Construct a new ActionBarDrawerToggle.
The given Activity
will be linked to the specified DrawerLayout
.
The provided drawer indicator drawable will animate slightly off-screen as the drawer
is opened, indicating that in the open state the drawer will move off-screen when pressed
and in the closed state the drawer will move on-screen when pressed.
String resources must be provided to describe the open/close drawer actions for accessibility services.
Parameters | |
---|---|
activity |
Activity : The Activity hosting the drawer |
drawerLayout |
DrawerLayout : The DrawerLayout to link to the given Activity's ActionBar |
animate |
boolean : True to animate the drawer indicator along with the drawer's position.
Material apps should set this to false. |
drawerImageRes |
int : A Drawable resource to use as the drawer indicator |
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
isDrawerIndicatorEnabled
boolean isDrawerIndicatorEnabled ()
Returns | |
---|---|
boolean |
true if the enhanced drawer indicator is enabled, false otherwise |
See also:
onConfigurationChanged
void onConfigurationChanged (Configuration newConfig)
This method should always be called by your Activity
's
onConfigurationChanged
method.
Parameters | |
---|---|
newConfig |
Configuration : The new configuration
|
onDrawerClosed
void onDrawerClosed (View drawerView)
DrawerLayout.DrawerListener
callback method. If you do not use your
ActionBarDrawerToggle instance directly as your DrawerLayout's listener, you should call
through to this method from your own listener object.
Parameters | |
---|---|
drawerView |
View : Drawer view that is now closed
|
onDrawerOpened
void onDrawerOpened (View drawerView)
DrawerLayout.DrawerListener
callback method. If you do not use your
ActionBarDrawerToggle instance directly as your DrawerLayout's listener, you should call
through to this method from your own listener object.
Parameters | |
---|---|
drawerView |
View : Drawer view that is now open
|
onDrawerSlide
void onDrawerSlide (View drawerView, float slideOffset)
DrawerLayout.DrawerListener
callback method. If you do not use your
ActionBarDrawerToggle instance directly as your DrawerLayout's listener, you should call
through to this method from your own listener object.
Parameters | |
---|---|
drawerView |
View : The child view that was moved |
slideOffset |
float : The new offset of this drawer within its range, from 0-1
|
onDrawerStateChanged
void onDrawerStateChanged (int newState)
DrawerLayout.DrawerListener
callback method. If you do not use your
ActionBarDrawerToggle instance directly as your DrawerLayout's listener, you should call
through to this method from your own listener object.
Parameters | |
---|---|
newState |
int : The new drawer motion state
|
onOptionsItemSelected
boolean onOptionsItemSelected (MenuItem item)
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 |
MenuItem : the MenuItem instance representing the selected menu item |
Returns | |
---|---|
boolean |
true if the event was handled and further processing should not occur |
setDrawerIndicatorEnabled
void setDrawerIndicatorEnabled (boolean enable)
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 |
boolean : true to enable, false to disable
|
setHomeAsUpIndicator
void setHomeAsUpIndicator (int resId)
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 |
int : Resource ID of a drawable to use for the up indicator, or 0
to use the theme's default |
See also:
setHomeAsUpIndicator
void setHomeAsUpIndicator (Drawable indicator)
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 |
Drawable : A drawable to use for the up indicator, or null to use
the theme's default |
See also:
syncState
void syncState ()
Synchronize the state of the drawer indicator/affordance with the linked DrawerLayout.
This should be called from your Activity
's
onPostCreate
method to synchronize after
the DrawerLayout's instance state has been restored, and any other time when the state
may have diverged in such a way that the ActionBarDrawerToggle was not notified.
(For example, if you stop forwarding appropriate drawer events for a period of time.)
Annotations
Interfaces
- ActionBarDrawerToggle.Delegate
- ActionBarDrawerToggle.DelegateProvider
- ActivityCompat.OnRequestPermissionsResultCallback
- ActivityCompat.PermissionCompatDelegate
- FragmentManager.BackStackEntry
- FragmentManager.OnBackStackChangedListener
- LoaderManager.LoaderCallbacks
- NotificationCompat.Action.Extender
- NotificationCompat.Extender
- SharedElementCallback.OnSharedElementsReadyListener
- TaskStackBuilder.SupportParentable
Classes
- ActionBarDrawerToggle
- ActivityCompat
- ActivityManagerCompat
- ActivityOptionsCompat
- AlarmManagerCompat
- AppLaunchChecker
- AppOpsManagerCompat
- BundleCompat
- DialogFragment
- Fragment
- Fragment.SavedState
- FragmentActivity
- FragmentContainer
- FragmentController
- FragmentHostCallback
- FragmentManager
- FragmentManager.FragmentLifecycleCallbacks
- FragmentManagerNonConfig
- FragmentPagerAdapter
- FragmentStatePagerAdapter
- FragmentTabHost
- FragmentTransaction
- FrameMetricsAggregator
- JobIntentService
- ListFragment
- LoaderManager
- NavUtils
- NotificationCompat
- NotificationCompat.Action
- NotificationCompat.Action.Builder
- NotificationCompat.Action.WearableExtender
- NotificationCompat.BigPictureStyle
- NotificationCompat.BigTextStyle
- NotificationCompat.Builder
- NotificationCompat.CarExtender
- NotificationCompat.CarExtender.UnreadConversation
- NotificationCompat.CarExtender.UnreadConversation.Builder
- NotificationCompat.DecoratedCustomViewStyle
- NotificationCompat.InboxStyle
- NotificationCompat.MessagingStyle
- NotificationCompat.MessagingStyle.Message
- NotificationCompat.Style
- NotificationCompat.WearableExtender
- NotificationCompatExtras
- NotificationCompatSideChannelService
- NotificationManagerCompat
- RemoteInput
- RemoteInput.Builder
- ServiceCompat
- ShareCompat
- ShareCompat.IntentBuilder
- ShareCompat.IntentReader
- SharedElementCallback
- TaskStackBuilder
Exceptions
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.