DrawerLayout


public class DrawerLayout extends ViewGroup implements Openable


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

Listener for monitoring events about drawers.

protected class DrawerLayout.SavedState extends AbsSavedState

State persisted across instances

Stub/no-op implementations of all methods of DrawerListener.

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

Indicates that a drawer is currently being dragged by the user.

static final int

Indicates that any drawers are in an idle, settled state.

static final int

Indicates that a drawer is in the process of settling to a final position.

Public constructors

DrawerLayout(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

void

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 the START drawer by animating it out of view.

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
float

The base elevation of the drawer(s) relative to the parent, in pixels.

int

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

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

Check if a given drawer view is currently visible on-screen.

boolean

Check if the START drawer is currently in an open state.

void
boolean
boolean
onKeyDown(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
void
onRtlPropertiesChanged(int layoutDirection)
boolean
void

Open the START drawer by animating it into view.

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.

Use addDrawerListener

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

Set a drawable to draw in the insets area for the status bar.

void

Set a drawable to draw in the insets area for the status bar.

Protected methods

boolean
boolean
drawChild(@NonNull Canvas canvas, View child, long drawingTime)
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
@NonNull Parcelable

Inherited Constants

From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From android.view.View
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
boolean
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
boolean

This method is deprecated.

void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable
int
BlendMode
ColorStateList
PorterDuff.Mode
boolean
getGlobalVisibleRect(Rect r, Point globalOffset)
Handler
float
float
float
float
Runnable
final boolean
final int
void
getHitRect(Rect outRect)
int
int
Drawable
Drawable
int
int
int
int
boolean
KeyEvent.DispatcherState
int
int
int
ViewGroup.LayoutParams
final int
float
int
final boolean
void
getLocationInSurface(int[] location)
void
getLocationInWindow(int[] outLocation)
void
getLocationOnScreen(int[] outLocation)
Matrix
final int
final int
final int
final int
final int
int
int
int
int
int
int
int
int
View.OnFocusChangeListener
int
ViewOutlineProvider
int
int
ViewOverlay
int
int
int
int
int
int
final ViewParent
ViewParent
float
float
PointerIcon
final List<Rect>
String[]
Resources
final boolean
final int
float
int
AttachedSurfaceControl
View
WindowInsets
float
float
float
float
float
int
int
int
int
int
int
final int
final int
int
int
final CharSequence
StateListAnimator
int
int
List<Rect>
int

This method is deprecated.

Object
int
int
CharSequence
final int
float
int
TouchDelegate
ArrayList<View>
float
String
float
float
float
long
int
int
Drawable
Drawable
int
ViewTranslationResponse
ViewTreeObserver
int
final int
int
WindowId
WindowInsetsController
int

This method is deprecated.

IBinder
int
void
float
float
float
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
static View
inflate(Context context, int resource, ViewGroup root)
void

This method is deprecated.

void
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean

This method is deprecated.

boolean
boolean
final boolean
final boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
final boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
View
keyboardNavigationClusterSearch(View currentCluster, int direction)
final void
measure(int widthMeasureSpec, int heightMeasureSpec)
static int[]
mergeDrawableStates(int[] baseState, int[] additionalState)
void
offsetLeftAndRight(int offset)
void
offsetTopAndBottom(int offset)
void
void
WindowInsets
void
boolean
boolean
void
void
InputConnection
void
onCreateViewTranslationRequest(
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onCreateVirtualViewTranslationRequests(
    long[] virtualIds,
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onDisplayHint(int hint)
boolean
void
final void
boolean
void
void
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    Rect previouslyFocusedRect
)
boolean
void
onHoverChanged(boolean hovered)
boolean
void
void
boolean
onKeyLongPress(int keyCode, KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean
onKeyPreIme(int keyCode, KeyEvent event)
boolean
onKeyShortcut(int keyCode, KeyEvent event)
void
onOverScrolled(
    int scrollX,
    int scrollY,
    boolean clampedX,
    boolean clampedY
)
void
onPointerCaptureChange(boolean hasCapture)
void
void
onProvideAutofillStructure(ViewStructure structure, int flags)
void
void
void
void
ContentInfo
void
onScreenStateChanged(int screenState)
void
onScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
onScrollChanged(int l, int t, int oldl, int oldt)
boolean
onSetAlpha(int alpha)
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
boolean
void
void
void
onVisibilityAggregated(boolean isVisible)
void
onVisibilityChanged(View changedView, int visibility)
void
onWindowFocusChanged(boolean hasWindowFocus)
void

This method is deprecated.

void
onWindowVisibilityChanged(int visibility)
boolean
overScrollBy(
    int deltaX,
    int deltaY,
    int scrollX,
    int scrollY,
    int scrollRangeX,
    int scrollRangeY,
    int maxOverScrollX,
    int maxOverScrollY,
    boolean isTouchEvent
)
boolean
performAccessibilityAction(int action, Bundle arguments)
boolean
boolean
performContextClick(float x, float y)
boolean
performHapticFeedback(int feedbackConstant)
boolean
ContentInfo
void
playSoundEffect(int soundConstant)
boolean
post(Runnable action)
boolean
postDelayed(Runnable action, long delayMillis)
void
void
postInvalidateDelayed(long delayMilliseconds)
void
void
void
postOnAnimationDelayed(Runnable action, long delayMillis)
void
void
boolean
void
void
void
void
void

This method is deprecated.

final boolean
void
boolean
final void
final T
<T extends View> requireViewById(int id)
void
static int
resolveSize(int size, int measureSpec)
static int
resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
void
final void
saveAttributeDataForStyleable(
    Context context,
    int[] styleable,
    AttributeSet attrs,
    TypedArray t,
    int defStyleAttr,
    int defStyleRes
)
void
void
scheduleDrawable(Drawable who, Runnable what, long when)
void
scrollBy(int x, int y)
void
scrollTo(int x, int y)
void
sendAccessibilityEvent(int eventType)
void
void
setAccessibilityDataSensitive(int accessibilityDataSensitive)
void
void
setAccessibilityHeading(boolean isHeading)
void
void
setAccessibilityPaneTitle(CharSequence accessibilityPaneTitle)
void
void
void
setActivated(boolean activated)
void
setAllowClickWhenDisabled(boolean clickableWhenDisabled)
void
void
void
setAlpha(float alpha)
void
void
void
setAutoHandwritingEnabled(boolean enabled)
void
setAutofillHints(String[] autofillHints)
void
void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void

This method is deprecated.

void
void
void
void
final void
setBottom(int bottom)
void
setCameraDistance(float distance)
void
setClickable(boolean clickable)
void
setClipBounds(Rect clipBounds)
void
setClipToOutline(boolean clipToOutline)
void
void
setContentDescription(CharSequence contentDescription)
void
setContextClickable(boolean contextClickable)
void
setDefaultFocusHighlightEnabled(boolean defaultFocusHighlightEnabled)
void

This method is deprecated.

void
setDrawingCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void
setElevation(float elevation)
void
setEnabled(boolean enabled)
void
setFadingEdgeLength(int length)
void
void
setFitsSystemWindows(boolean fitSystemWindows)
void
setFocusable(boolean focusable)
void
setFocusableInTouchMode(boolean focusableInTouchMode)
void
setFocusedByDefault(boolean isFocusedByDefault)
void
setForceDarkAllowed(boolean allow)
void
setForeground(Drawable foreground)
void
setForegroundGravity(int gravity)
void
void
void
void
setHandwritingBoundsOffsets(
    float offsetLeft,
    float offsetTop,
    float offsetRight,
    float offsetBottom
)
void
void
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
void
setHasTransientState(boolean hasTransientState)
void
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
void
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
void
void
void
setHovered(boolean hovered)
void
setId(int id)
void
void
void
void
setIsCredential(boolean isCredential)
void
setIsHandwritingDelegate(boolean isHandwritingDelegate)
void
setKeepScreenOn(boolean keepScreenOn)
void
setKeyboardNavigationCluster(boolean isCluster)
void
setLabelFor(int id)
void
void
setLayerType(int layerType, Paint paint)
void
setLayoutDirection(int layoutDirection)
void
final void
setLeft(int left)
final void
setLeftTopRightBottom(int left, int top, int right, int bottom)
void
setLongClickable(boolean longClickable)
final void
setMeasuredDimension(int measuredWidth, int measuredHeight)
void
setMinimumHeight(int minHeight)
void
setMinimumWidth(int minWidth)
void
setNestedScrollingEnabled(boolean enabled)
void
setNextClusterForwardId(int nextClusterForwardId)
void
setNextFocusDownId(int nextFocusDownId)
void
setNextFocusForwardId(int nextFocusForwardId)
void
setNextFocusLeftId(int nextFocusLeftId)
void
setNextFocusRightId(int nextFocusRightId)
void
setNextFocusUpId(int nextFocusUpId)
void
void
void
void
void
void
void
void
void
void
void
void
setOnReceiveContentListener(
    String[] mimeTypes,
    OnReceiveContentListener listener
)
void
void

This method is deprecated.

void
void
void
void
void
setOverScrollMode(int overScrollMode)
void
setPadding(int left, int top, int right, int bottom)
void
setPaddingRelative(int start, int top, int end, int bottom)
void
setPivotX(float pivotX)
void
setPivotY(float pivotY)
void
final void
setPreferKeepClear(boolean preferKeepClear)
final void
void
setPressed(boolean pressed)
void
final void
setRevealOnFocusHint(boolean revealOnFocus)
final void
setRight(int right)
void
setRotation(float rotation)
void
setRotationX(float rotationX)
void
setRotationY(float rotationY)
void
setSaveEnabled(boolean enabled)
void
setSaveFromParentEnabled(boolean enabled)
void
setScaleX(float scaleX)
void
setScaleY(float scaleY)
void
setScreenReaderFocusable(boolean screenReaderFocusable)
void
setScrollBarDefaultDelayBeforeFade(
    int scrollBarDefaultDelayBeforeFade
)
void
setScrollBarFadeDuration(int scrollBarFadeDuration)
void
setScrollBarSize(int scrollBarSize)
void
setScrollBarStyle(int style)
final void
void
void
setScrollContainer(boolean isScrollContainer)
void
setScrollIndicators(int indicators)
void
setScrollX(int value)
void
setScrollY(int value)
void
setScrollbarFadingEnabled(boolean fadeScrollbars)
void
setSelected(boolean selected)
void
setSoundEffectsEnabled(boolean soundEffectsEnabled)
void
void
void
void
setSystemUiVisibility(int visibility)

This method is deprecated.

void
void
setTextAlignment(int textAlignment)
void
setTextDirection(int textDirection)
void
final void
setTop(int top)
void
void
setTransitionAlpha(float alpha)
final void
setTransitionName(String transitionName)
void
setTransitionVisibility(int visibility)
void
setTranslationX(float translationX)
void
setTranslationY(float translationY)
void
setTranslationZ(float translationZ)
void
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
void
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
void
void
void
void
void
setVisibility(int visibility)
void
setWillNotCacheDrawing(boolean willNotCacheDrawing)

This method is deprecated.

void
setWillNotDraw(boolean willNotDraw)
void
setX(float x)
void
setY(float y)
void
setZ(float z)
boolean
ActionMode
void
final boolean
startDrag(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)

This method is deprecated.

final boolean
startDragAndDrop(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)
boolean
void
String
void
void
void
final void
boolean
boolean

This method is deprecated.

boolean
From android.view.ViewGroup
void
void
addExtraDataToAccessibilityNodeInfo(
    AccessibilityNodeInfo info,
    String extraDataKey,
    Bundle arguments
)
void
boolean
void
void
addView(View child)
boolean
addViewInLayout(View child, int index, ViewGroup.LayoutParams params)
void
attachLayoutAnimationParameters(
    View child,
    ViewGroup.LayoutParams params,
    int index,
    int count
)
void
attachViewToParent(View child, int index, ViewGroup.LayoutParams params)
void
boolean
void
void
childHasTransientStateChanged(
    View child,
    boolean childHasTransientState
)
void
void
void
void
void
debug(int depth)
void
void
void
detachViewsFromParent(int start, int count)
WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    Map<AutofillId, long[]> viewIds,
    int[] supportedFormats,
    TranslationCapability capability,
    List<ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
void
boolean
boolean
boolean
boolean
boolean
boolean
void
dispatchPointerCaptureChanged(boolean hasCapture)
void
void
void
void
void
dispatchScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated.

void
boolean
boolean
boolean
dispatchUnhandledMove(View focused, int direction)
void
dispatchVisibilityChanged(View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
WindowInsets
WindowInsetsAnimation.Bounds
void

This method is deprecated.

void
void
void
View
OnBackInvokedDispatcher
void
findViewsWithText(
    ArrayList<View> outViews,
    CharSequence text,
    int flags
)
View
focusSearch(View focused, int direction)
void
boolean
CharSequence
View
getChildAt(int index)
int
int
getChildDrawingOrder(int childCount, int drawingPosition)
static int
getChildMeasureSpec(int spec, int padding, int childDimension)
boolean
boolean
getChildVisibleRect(View child, Rect r, Point offset)
boolean
boolean
int
View
LayoutAnimationController
Animation.AnimationListener
int
LayoutTransition
int
ViewGroupOverlay
int

This method is deprecated.

boolean
boolean
boolean
int
final void
invalidateChild(View child, Rect dirty)

This method is deprecated.

ViewParent
invalidateChildInParent(int[] location, Rect dirty)

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

boolean
boolean

This method is deprecated.

boolean
boolean
boolean
void
final void
layout(int l, int t, int r, int b)
void
measureChild(
    View child,
    int parentWidthMeasureSpec,
    int parentHeightMeasureSpec
)
void
measureChildWithMargins(
    View child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)
void
measureChildren(int widthMeasureSpec, int heightMeasureSpec)
void
notifySubtreeAccessibilityStateChanged(
    View child,
    View source,
    int changeType
)
final void
final void
int[]
onCreateDrawableState(int extraSpace)
void
boolean
boolean
onNestedFling(
    View target,
    float velocityX,
    float velocityY,
    boolean consumed
)
boolean
onNestedPreFling(View target, float velocityX, float velocityY)
boolean
onNestedPrePerformAccessibilityAction(
    View target,
    int action,
    Bundle args
)
void
onNestedPreScroll(View target, int dx, int dy, int[] consumed)
void
onNestedScroll(
    View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed
)
void
onNestedScrollAccepted(View child, View target, int axes)
boolean
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
boolean
PointerIcon
onResolvePointerIcon(MotionEvent event, int pointerIndex)
boolean
onStartNestedScroll(View child, View target, int nestedScrollAxes)
void
void
void
void
void
void
void
removeDetachedView(View child, boolean animate)
void
void
removeViewAt(int index)
void
void
removeViews(int start, int count)
void
removeViewsInLayout(int start, int count)
void
requestChildFocus(View child, View focused)
boolean
requestChildRectangleOnScreen(
    View child,
    Rect rectangle,
    boolean immediate
)
boolean
requestFocus(int direction, Rect previouslyFocusedRect)
boolean
void
boolean
void
void
setAddStatesFromChildren(boolean addsStates)
void

This method is deprecated.

void
setAnimationCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void

This method is deprecated.

void
setClipChildren(boolean clipChildren)
void
setClipToPadding(boolean clipToPadding)
void
setDescendantFocusability(int focusability)
void
void
void
setLayoutMode(int layoutMode)
void
void
void
void
setPersistentDrawingCache(int drawingCacheToKeep)

This method is deprecated.

void
void
setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus)
void
setTransitionGroup(boolean isTransitionGroup)
void
boolean
boolean
ActionMode
startActionModeForChild(
    View originalView,
    ActionMode.Callback callback
)
void
void
void
suppressLayout(boolean suppress)
void

Constants

LOCK_MODE_LOCKED_CLOSED

Added in 1.0.0
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

Added in 1.0.0
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

Added in 1.0.0
public static final int LOCK_MODE_UNDEFINED = 3

The drawer's lock state is reset to default.

LOCK_MODE_UNLOCKED

Added in 1.0.0
public static final int LOCK_MODE_UNLOCKED = 0

The drawer is unlocked.

STATE_DRAGGING

Added in 1.0.0
public static final int STATE_DRAGGING = 1

Indicates that a drawer is currently being dragged by the user.

STATE_IDLE

Added in 1.0.0
public static final int STATE_IDLE = 0

Indicates that any drawers are in an idle, settled state. No animation is in progress.

STATE_SETTLING

Added in 1.0.0
public static final int STATE_SETTLING = 2

Indicates that a drawer is in the process of settling to a final position.

Public constructors

DrawerLayout

Added in 1.0.0
public DrawerLayout(@NonNull Context context)

DrawerLayout

Added in 1.0.0
public DrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs)

DrawerLayout

Added in 1.0.0
public DrawerLayout(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

addDrawerListener

Added in 1.0.0
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.

addFocusables

public void addFocusables(ArrayList<View> views, int direction, int focusableMode)

addView

public void addView(View child, int index, ViewGroup.LayoutParams params)

close

Added in 1.1.0
public void close()

Close the START drawer by animating it out of view.

closeDrawer

Added in 1.0.0
public void closeDrawer(@NonNull View drawerView)

Close the specified drawer view by animating it into view.

Parameters
@NonNull View drawerView

Drawer view to close

closeDrawer

Added in 1.0.0
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

Added in 1.0.0
public void closeDrawer(@NonNull View drawerView, boolean animate)

Close the specified drawer view.

Parameters
@NonNull View drawerView

Drawer view to close

boolean animate

Whether closing of the drawer should be animated.

closeDrawer

Added in 1.0.0
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

Added in 1.0.0
public void closeDrawers()

Close all currently open drawer views by animating them out of view.

computeScroll

public void computeScroll()

dispatchGenericMotionEvent

public boolean dispatchGenericMotionEvent(MotionEvent event)

generateLayoutParams

public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)

getDrawerElevation

Added in 1.0.0
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

Added in 1.0.0
public int getDrawerLockMode(@NonNull View drawerView)

Check the lock mode of the given drawer view.

Parameters
@NonNull View drawerView

Drawer view to check lock mode

getDrawerLockMode

Added in 1.0.0
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

getDrawerTitle

Added in 1.0.0
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

Added in 1.0.0
public @Nullable Drawable getStatusBarBackgroundDrawable()

Gets the drawable used to draw in the insets area for the status bar.

Returns
@Nullable Drawable

The status bar background drawable, or null if none set

isDrawerOpen

Added in 1.0.0
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

Added in 1.0.0
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.

Parameters
@NonNull View drawer

Drawer view to check

Returns
boolean

true if the given drawer view is in an open state

See also
isDrawerVisible

isDrawerVisible

Added in 1.0.0
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

Added in 1.0.0
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.

Parameters
@NonNull View drawer

Drawer view to check

Returns
boolean

true if the given drawer is visible on-screen

See also
isDrawerOpen

isOpen

Added in 1.1.0
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 START drawer is in an open state

onDraw

Added in 1.0.0
public void onDraw(@NonNull Canvas c)

onInterceptTouchEvent

public boolean onInterceptTouchEvent(MotionEvent ev)

onKeyDown

public boolean onKeyDown(int keyCode, KeyEvent event)

onKeyUp

public boolean onKeyUp(int keyCode, KeyEvent event)

onRtlPropertiesChanged

public void onRtlPropertiesChanged(int layoutDirection)

onTouchEvent

public boolean onTouchEvent(MotionEvent ev)

open

Added in 1.1.0
public void open()

Open the START drawer by animating it into view.

openDrawer

Added in 1.0.0
public void openDrawer(@NonNull View drawerView)

Open the specified drawer view by animating it into view.

Parameters
@NonNull View drawerView

Drawer view to open

openDrawer

Added in 1.0.0
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

Added in 1.0.0
public void openDrawer(@NonNull View drawerView, boolean animate)

Open the specified drawer view.

Parameters
@NonNull View drawerView

Drawer view to open

boolean animate

Whether opening of the drawer should be animated.

openDrawer

Added in 1.0.0
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

Added in 1.0.0
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

requestDisallowInterceptTouchEvent

public void requestDisallowInterceptTouchEvent(boolean disallowIntercept)

requestLayout

public void requestLayout()

setDrawerElevation

Added in 1.0.0
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.

setDrawerListener

Added in 1.0.0
Deprecated in 1.0.0
public void setDrawerListener(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

Added in 1.0.0
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 LOCK_MODE_UNLOCKED, LOCK_MODE_LOCKED_CLOSED or LOCK_MODE_LOCKED_OPEN.

setDrawerLockMode

Added in 1.0.0
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 LOCK_MODE_UNLOCKED, LOCK_MODE_LOCKED_CLOSED or LOCK_MODE_LOCKED_OPEN.

@NonNull View drawerView

The drawer view to change the lock mode for

setDrawerLockMode

Added in 1.0.0
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 LOCK_MODE_UNLOCKED, LOCK_MODE_LOCKED_CLOSED or LOCK_MODE_LOCKED_OPEN.

int edgeGravity

Gravity.LEFT, RIGHT, START or END. Expresses which drawer to change the mode for.

setDrawerShadow

Added in 1.0.0
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

Added in 1.0.0
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.

Parameters
@Nullable Drawable shadowDrawable

Shadow drawable to use at the edge of a drawer

int gravity

Which drawer the shadow should apply to

setDrawerTitle

Added in 1.0.0
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

Added in 1.0.0
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

Added in 1.0.0
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.

Parameters
@Nullable Drawable bg

Background drawable to draw behind the status bar

setStatusBarBackground

Added in 1.0.0
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

Added in 1.0.0
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

checkLayoutParams

protected boolean checkLayoutParams(ViewGroup.LayoutParams p)

drawChild

protected boolean drawChild(@NonNull Canvas canvas, View child, long drawingTime)

generateDefaultLayoutParams

protected ViewGroup.LayoutParams generateDefaultLayoutParams()

onAttachedToWindow

protected void onAttachedToWindow()

onDetachedFromWindow

protected void onDetachedFromWindow()

onLayout

protected void onLayout(boolean changed, int l, int t, int r, int b)

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)

onSaveInstanceState

protected @NonNull Parcelable onSaveInstanceState()