Google is committed to advancing racial equity for Black communities. See how.

DrawerLayout

open class DrawerLayout : ViewGroup, Openable
kotlin.Any
   ↳ 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 classes
abstract

Listener for monitoring events about drawers.

open

open

State persisted across instances

abstract

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

Constants
static Int

The drawer is locked closed.

static Int

The drawer is locked open.

static Int

The drawer's lock state is reset to default.

static Int

The drawer is unlocked.

static Int

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

static Int

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

static Int

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

Public constructors
<init>(@NonNull context: Context)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int)

Public methods
open Unit

Adds the specified listener to the list of listeners that will be notified of drawer events.

open Unit
addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int)

open Unit
addView(child: View!, index: Int, params: LayoutParams!)

open Unit

Close the GravityCompat#START drawer by animating it out of view.

open Unit
closeDrawer(@NonNull drawerView: View)

Close the specified drawer view by animating it into view.

open Unit
closeDrawer(@NonNull drawerView: View, animate: Boolean)

Close the specified drawer view.

open Unit
closeDrawer(gravity: Int)

Close the specified drawer by animating it out of view.

open Unit
closeDrawer(gravity: Int, animate: Boolean)

Close the specified drawer.

open Unit

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

open Unit

open Boolean

open LayoutParams!

open Float

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

open Int
getDrawerLockMode(edgeGravity: Int)

Check the lock mode of the drawer with the given gravity.

open Int
getDrawerLockMode(@NonNull drawerView: View)

Check the lock mode of the given drawer view.

open CharSequence?
getDrawerTitle(edgeGravity: Int)

Returns the title of the drawer with the given gravity.

open Drawable?

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

open Boolean
isDrawerOpen(@NonNull drawer: View)

Check if the given drawer view is currently in an open state.

open Boolean
isDrawerOpen(drawerGravity: Int)

Check if the given drawer view is currently in an open state.

open Boolean
isDrawerVisible(@NonNull drawer: View)

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

open Boolean
isDrawerVisible(drawerGravity: Int)

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

open Boolean

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

open Unit

open Boolean

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

open Boolean

open Unit

Open the GravityCompat#START drawer by animating it into view.

open Unit
openDrawer(@NonNull drawerView: View)

Open the specified drawer view by animating it into view.

open Unit
openDrawer(@NonNull drawerView: View, animate: Boolean)

Open the specified drawer view.

open Unit
openDrawer(gravity: Int)

Open the specified drawer by animating it out of view.

open Unit
openDrawer(gravity: Int, animate: Boolean)

Open the specified drawer.

open Unit

Removes the specified listener from the list of listeners that will be notified of drawer events.

open Unit

open Unit

open Unit

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

open Unit

Set a listener to be notified of drawer events.

open Unit