DrawerLayout
public class DrawerLayout extends ViewGroup implements Openable
| java.lang.Object | |||
| ↳ | android.view.View | ||
| ↳ | android.view.ViewGroup | ||
| ↳ | androidx.drawerlayout.widget.DrawerLayout |
DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.
Drawer positioning and layout is controlled using the android:layout_gravity attribute on child views corresponding to which side of the view you want the drawer to emerge from: left or right (or start/end on platform versions that support layout direction.) Note that you can only have one drawer view for each vertical edge of the window. If your layout configures more than one drawer view per vertical edge of the window, an exception will be thrown at runtime.
To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity>. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
DrawerListener can be used to monitor the state and motion of drawer views. Avoid performing expensive operations such as layout during animation as it can cause stuttering; try to perform expensive operations during the STATE_IDLE state. SimpleDrawerListener offers default/no-op implementations of each callback method.
As per the Android Design guide, any drawers positioned to the left/start should always contain content for navigating around the application, whereas any drawers positioned to the right/end should always contain actions to take on the current content. This preserves the same navigation left, actions right structure present in the Action Bar and elsewhere.
For more information about how to use DrawerLayout, read Creating a Navigation Drawer.
Summary
Nested types |
|---|
public interface DrawerLayout.DrawerListenerListener for monitoring events about drawers. |
public class DrawerLayout.LayoutParams extends ViewGroup.MarginLayoutParams |
protected class DrawerLayout.SavedState extends AbsSavedStateState persisted across instances |
public abstract class DrawerLayout.SimpleDrawerListener implements DrawerLayout.DrawerListenerStub/no-op implementations of all methods of |
Constants |
|
|---|---|
static final int |
The drawer is locked closed. |
static final int |
The drawer is locked open. |
static final int |
The drawer's lock state is reset to default. |
static final int |
The drawer is unlocked. |
static final int |
STATE_DRAGGING = 1Indicates that a drawer is currently being dragged by the user. |
static final int |
STATE_IDLE = 0Indicates that any drawers are in an idle, settled state. |
static final int |
STATE_SETTLING = 2Indicates that a drawer is in the process of settling to a final position. |
Public constructors |
|---|
DrawerLayout(@NonNull Context context) |
DrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs) |
DrawerLayout( |
Public methods |
|
|---|---|
void |
addDrawerListener(@NonNull DrawerLayout.DrawerListener listener)Adds the specified listener to the list of listeners that will be notified of drawer events. |
void |
addFocusables(ArrayList<View> views, int direction, int focusableMode) |
void |
addView(View child, int index, ViewGroup.LayoutParams params) |
void |
close()Close the |
void |
closeDrawer(@NonNull View drawerView)Close the specified drawer view by animating it into view. |
void |
closeDrawer(int gravity)Close the specified drawer by animating it out of view. |
void |
closeDrawer(@NonNull View drawerView, boolean animate)Close the specified drawer view. |
void |
closeDrawer(int gravity, boolean animate)Close the specified drawer. |
void |
Close all currently open drawer views by animating them out of view. |
void |
|
boolean |
|
ViewGroup.LayoutParams |
generateLayoutParams(AttributeSet attrs) |
float |
The base elevation of the drawer(s) relative to the parent, in pixels. |
int |
getDrawerLockMode(@NonNull View drawerView)Check the lock mode of the given drawer view. |
int |
getDrawerLockMode(int edgeGravity)Check the lock mode of the drawer with the given gravity. |
@Nullable CharSequence |
getDrawerTitle(int edgeGravity)Returns the title of the drawer with the given gravity. |
@Nullable Drawable |
Gets the drawable used to draw in the insets area for the status bar. |
boolean |
isDrawerOpen(int drawerGravity)Check if the given drawer view is currently in an open state. |
boolean |
isDrawerOpen(@NonNull View drawer)Check if the given drawer view is currently in an open state. |
boolean |
isDrawerVisible(int drawerGravity)Check if a given drawer view is currently visible on-screen. |
boolean |
isDrawerVisible(@NonNull View drawer)Check if a given drawer view is currently visible on-screen. |
boolean |
isOpen()Check if the |
void |
|
boolean |
|
boolean |
|
boolean |
|
void |
onRtlPropertiesChanged(int layoutDirection) |
boolean |
|
void |
open()Open the |
void |
openDrawer(@NonNull View drawerView)Open the specified drawer view by animating it into view. |
void |
openDrawer(int gravity)Open the specified drawer by animating it out of view. |
void |
openDrawer(@NonNull View drawerView, boolean animate)Open the specified drawer view. |
void |
openDrawer(int gravity, boolean animate)Open the specified drawer. |
void |
Removes the specified listener from the list of listeners that will be notified of drawer events. |
void |
requestDisallowInterceptTouchEvent(boolean disallowIntercept) |
void |
|
void |
setDrawerElevation(float elevation)Sets the base elevation of the drawer(s) relative to the parent, in pixels. |
void |
This method is deprecated. |
void |
setDrawerLockMode(int lockMode)Enable or disable interaction with all drawers. |
void |
setDrawerLockMode(int lockMode, @NonNull View drawerView)Enable or disable interaction with the given drawer. |
void |
setDrawerLockMode(int lockMode, int edgeGravity)Enable or disable interaction with the given drawer. |
void |
setDrawerShadow(@DrawableRes int resId, int gravity)Set a simple drawable used for the left or right shadow. |
void |
setDrawerShadow(@Nullable Drawable shadowDrawable, int gravity)Set a simple drawable used for the left or right shadow. |
void |
setDrawerTitle(int edgeGravity, @Nullable CharSequence title)Sets the title of the drawer with the given gravity. |
void |
setScrimColor(@ColorInt int color)Set a color to use for the scrim that obscures primary content while a drawer is open. |
void |
Set a drawable to draw in the insets area for the status bar. |
void |
setStatusBarBackground(int resId)Set a drawable to draw in the insets area for the status bar. |
void |
setStatusBarBackgroundColor(@ColorInt int color)Set a drawable to draw in the insets area for the status bar. |
Protected methods |
|
|---|---|
boolean |
|
boolean |
|
ViewGroup.LayoutParams |
|
ViewGroup.LayoutParams |
|
void |
|
void |
|
void |
onLayout(boolean changed, int l, int t, int r, int b) |
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
void |
onRestoreInstanceState(Parcelable state) |
@NonNull Parcelable |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
LOCK_MODE_LOCKED_CLOSED
public static final int LOCK_MODE_LOCKED_CLOSED = 1
The drawer is locked closed. The user may not open it, though the app may open it programmatically.
LOCK_MODE_LOCKED_OPEN
public static final int LOCK_MODE_LOCKED_OPEN = 2
The drawer is locked open. The user may not close it, though the app may close it programmatically.
LOCK_MODE_UNDEFINED
public static final int LOCK_MODE_UNDEFINED = 3
The drawer's lock state is reset to default.
LOCK_MODE_UNLOCKED
public static final int LOCK_MODE_UNLOCKED = 0
The drawer is unlocked.
STATE_DRAGGING
public static final int STATE_DRAGGING = 1
Indicates that a drawer is currently being dragged by the user.
STATE_IDLE
public static final int STATE_IDLE = 0
Indicates that any drawers are in an idle, settled state. No animation is in progress.
STATE_SETTLING
public static final int STATE_SETTLING = 2
Indicates that a drawer is in the process of settling to a final position.
Public constructors
DrawerLayout
public DrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs)
DrawerLayout
public DrawerLayout(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
Public methods
addDrawerListener
public void addDrawerListener(@NonNull DrawerLayout.DrawerListener listener)
Adds the specified listener to the list of listeners that will be notified of drawer events.
| Parameters | |
|---|---|
@NonNull DrawerLayout.DrawerListener listener |
Listener to notify when drawer events occur. |
| See also | |
|---|---|
removeDrawerListener |
closeDrawer
public void closeDrawer(@NonNull View drawerView)
Close the specified drawer view by animating it into view.
closeDrawer
public void closeDrawer(int gravity)
Close the specified drawer by animating it out of view.
| Parameters | |
|---|---|
int gravity |
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right. GravityCompat.START or GravityCompat.END may also be used. |
closeDrawer
public void closeDrawer(@NonNull View drawerView, boolean animate)
Close the specified drawer view.
closeDrawer
public void closeDrawer(int gravity, boolean animate)
Close the specified drawer.
| Parameters | |
|---|---|
int gravity |
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right. GravityCompat.START or GravityCompat.END may also be used. |
boolean animate |
Whether closing of the drawer should be animated. |
closeDrawers
public void closeDrawers()
Close all currently open drawer views by animating them out of view.
getDrawerElevation
public float getDrawerElevation()
The base elevation of the drawer(s) relative to the parent, in pixels. Note that the elevation change is only supported in API 21 and above. For unsupported API levels, 0 will be returned as the elevation.
| Returns | |
|---|---|
float |
The base depth position of the view, in pixels. |
getDrawerLockMode
public int getDrawerLockMode(@NonNull View drawerView)
Check the lock mode of the given drawer view.
| Returns | |
|---|---|
int |
one of |
getDrawerLockMode
public int getDrawerLockMode(int edgeGravity)
Check the lock mode of the drawer with the given gravity.
| Parameters | |
|---|---|
int edgeGravity |
Gravity of the drawer to check |
| Returns | |
|---|---|
int |
one of |
getDrawerTitle
public @Nullable CharSequence getDrawerTitle(int edgeGravity)
Returns the title of the drawer with the given gravity.
| Parameters | |
|---|---|
int edgeGravity |
Gravity.LEFT, RIGHT, START or END. Expresses which drawer to return the title for. |
| Returns | |
|---|---|
@Nullable CharSequence |
The title of the drawer, or null if none set. |
| See also | |
|---|---|
setDrawerTitle |
getStatusBarBackgroundDrawable
public @Nullable Drawable getStatusBarBackgroundDrawable()
Gets the drawable used to draw in the insets area for the status bar.
isDrawerOpen
public boolean isDrawerOpen(int drawerGravity)
Check if the given drawer view is currently in an open state. To be considered "open" the drawer must have settled into its fully visible state. If there is no drawer with the given gravity this method will return false.
| Parameters | |
|---|---|
int drawerGravity |
Gravity of the drawer to check |
| Returns | |
|---|---|
boolean |
true if the given drawer view is in an open state |
isDrawerOpen
public boolean isDrawerOpen(@NonNull View drawer)
Check if the given drawer view is currently in an open state. To be considered "open" the drawer must have settled into its fully visible state. To check for partial visibility use isDrawerVisible.
| Returns | |
|---|---|
boolean |
true if the given drawer view is in an open state |
| See also | |
|---|---|
isDrawerVisible |
isDrawerVisible
public boolean isDrawerVisible(int drawerGravity)
Check if a given drawer view is currently visible on-screen. The drawer may be only peeking onto the screen, fully extended, or anywhere in between. If there is no drawer with the given gravity this method will return false.
| Parameters | |
|---|---|
int drawerGravity |
Gravity of the drawer to check |
| Returns | |
|---|---|
boolean |
true if the given drawer is visible on-screen |
isDrawerVisible
public boolean isDrawerVisible(@NonNull View drawer)
Check if a given drawer view is currently visible on-screen. The drawer may be only peeking onto the screen, fully extended, or anywhere inbetween.
| Returns | |
|---|---|
boolean |
true if the given drawer is visible on-screen |
| See also | |
|---|---|
isDrawerOpen |
isOpen
public boolean isOpen()
Check if the START drawer is currently in an open state. To be considered "open" the drawer must have settled into its fully visible state. If there is no drawer with the given gravity this method will return false.
| Returns | |
|---|---|
boolean |
true if the |
openDrawer
public void openDrawer(@NonNull View drawerView)
Open the specified drawer view by animating it into view.
openDrawer
public void openDrawer(int gravity)
Open the specified drawer by animating it out of view.
| Parameters | |
|---|---|
int gravity |
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right. GravityCompat.START or GravityCompat.END may also be used. |
openDrawer
public void openDrawer(@NonNull View drawerView, boolean animate)
Open the specified drawer view.
openDrawer
public void openDrawer(int gravity, boolean animate)
Open the specified drawer.
| Parameters | |
|---|---|
int gravity |
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right. GravityCompat.START or GravityCompat.END may also be used. |
boolean animate |
Whether opening of the drawer should be animated. |
removeDrawerListener
public void removeDrawerListener(@NonNull DrawerLayout.DrawerListener listener)
Removes the specified listener from the list of listeners that will be notified of drawer events.
| Parameters | |
|---|---|
@NonNull DrawerLayout.DrawerListener listener |
Listener to remove from being notified of drawer events |
| See also | |
|---|---|
addDrawerListener |
requestDisallowInterceptTouchEvent
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
setDrawerElevation
public void setDrawerElevation(float elevation)
Sets the base elevation of the drawer(s) relative to the parent, in pixels. Note that the elevation change is only supported in API 21 and above.
| Parameters | |
|---|---|
float elevation |
The base depth position of the view, in pixels. |
public voidsetDrawerListener(DrawerLayout.DrawerListener listener)
Set a listener to be notified of drawer events. Note that this method is deprecated and you should use addDrawerListener to add a listener and removeDrawerListener to remove a registered listener.
| Parameters | |
|---|---|
DrawerLayout.DrawerListener listener |
Listener to notify when drawer events occur |
setDrawerLockMode
public void setDrawerLockMode(int lockMode)
Enable or disable interaction with all drawers.
This allows the application to restrict the user's ability to open or close any drawer within this layout. DrawerLayout will still respond to calls to openDrawer, closeDrawer and friends if a drawer is locked.
Locking drawers open or closed will implicitly open or close any drawers as appropriate.
| Parameters | |
|---|---|
int lockMode |
The new lock mode for the given drawer. One of |
setDrawerLockMode
public void setDrawerLockMode(int lockMode, @NonNull View drawerView)
Enable or disable interaction with the given drawer.
This allows the application to restrict the user's ability to open or close the given drawer. DrawerLayout will still respond to calls to openDrawer, closeDrawer and friends if a drawer is locked.
Locking a drawer open or closed will implicitly open or close that drawer as appropriate.
| Parameters | |
|---|---|
int lockMode |
The new lock mode for the given drawer. One of |
@NonNull View drawerView |
The drawer view to change the lock mode for |
setDrawerLockMode
public void setDrawerLockMode(int lockMode, int edgeGravity)
Enable or disable interaction with the given drawer.
This allows the application to restrict the user's ability to open or close the given drawer. DrawerLayout will still respond to calls to openDrawer, closeDrawer and friends if a drawer is locked.
Locking a drawer open or closed will implicitly open or close that drawer as appropriate.
| Parameters | |
|---|---|
int lockMode |
The new lock mode for the given drawer. One of |
int edgeGravity |
Gravity.LEFT, RIGHT, START or END. Expresses which drawer to change the mode for. |
setDrawerShadow
public void setDrawerShadow(@DrawableRes int resId, int gravity)
Set a simple drawable used for the left or right shadow. The drawable provided must have a nonzero intrinsic width. For API 21 and above, an elevation will be set on the drawer instead of using the provided shadow drawable.
Note that for better support for both left-to-right and right-to-left layout directions, a drawable for RTL layout (in additional to the one in LTR layout) can be defined with a resource qualifier "ldrtl" for API 17 and above with the gravity START. Alternatively, for API 23 and above, the drawable can auto-mirrored such that the drawable will be mirrored in RTL layout.
| Parameters | |
|---|---|
@DrawableRes int resId |
Resource id of a shadow drawable to use at the edge of a drawer |
int gravity |
Which drawer the shadow should apply to |
setDrawerShadow
public void setDrawerShadow(@Nullable Drawable shadowDrawable, int gravity)
Set a simple drawable used for the left or right shadow. The drawable provided must have a nonzero intrinsic width. For API 21 and above, an elevation will be set on the drawer instead of using the provided shadow drawable.
Note that for better support for both left-to-right and right-to-left layout directions, a drawable for RTL layout (in additional to the one in LTR layout) can be defined with a resource qualifier "ldrtl" for API 17 and above with the gravity START. Alternatively, for API 23 and above, the drawable can auto-mirrored such that the drawable will be mirrored in RTL layout.
setDrawerTitle
public void setDrawerTitle(int edgeGravity, @Nullable CharSequence title)
Sets the title of the drawer with the given gravity.
When accessibility is turned on, this is the title that will be used to identify the drawer to the active accessibility service.
| Parameters | |
|---|---|
int edgeGravity |
Gravity.LEFT, RIGHT, START or END. Expresses which drawer to set the title for. |
@Nullable CharSequence title |
The title for the drawer. |
setScrimColor
public void setScrimColor(@ColorInt int color)
Set a color to use for the scrim that obscures primary content while a drawer is open.
| Parameters | |
|---|---|
@ColorInt int color |
Color to use in 0xAARRGGBB format. |
setStatusBarBackground
public void setStatusBarBackground(@Nullable Drawable bg)
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
setStatusBarBackground
public void setStatusBarBackground(int resId)
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
| Parameters | |
|---|---|
int resId |
Resource id of a background drawable to draw behind the status bar |
setStatusBarBackgroundColor
public void setStatusBarBackgroundColor(@ColorInt int color)
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
| Parameters | |
|---|---|
@ColorInt int color |
Color to use as a background drawable to draw behind the status bar in 0xAARRGGBB format. |
Protected methods
generateLayoutParams
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)