DrawerLayout

(SESL variant) 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.

Constructors

Link copied to clipboard
constructor(@NonNull context: Context)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int)

Types

Link copied to clipboard
interface DrawerListener
Listener for monitoring events about drawers.
Link copied to clipboard
Link copied to clipboard
Stub/no-op implementations of all methods of DrawerListener.

Properties

Link copied to clipboard
The drawer is locked closed.
Link copied to clipboard
The drawer is locked open.
Link copied to clipboard
The drawer's lock state is reset to default.
Link copied to clipboard
The drawer is unlocked.
Link copied to clipboard
Indicates that a drawer is currently being dragged by the user.
Link copied to clipboard
val STATE_IDLE: Int = 0
Indicates that any drawers are in an idle, settled state.
Link copied to clipboard
Indicates that a drawer is in the process of settling to a final position.

Functions

Link copied to clipboard
Adds the specified listener to the list of listeners that will be notified of drawer events.
Link copied to clipboard
open fun addFocusables(views: ArrayList<View>, direction: Int, focusableMode: Int)
Link copied to clipboard
open fun addView(child: View, index: Int, params: ViewGroup.LayoutParams)
Link copied to clipboard
open fun close()
Close the START drawer by animating it out of view.
Link copied to clipboard
open fun closeDrawer(@NonNull drawerView: View)
Close the specified drawer view by animating it into view.
open fun closeDrawer(gravity: Int)
Close the specified drawer by animating it out of view.
open fun closeDrawer(@NonNull drawerView: View, animate: Boolean)
Close the specified drawer view.
open fun closeDrawer(gravity: Int, animate: Boolean)
Close the specified drawer.
Link copied to clipboard
open fun closeDrawers()
Close all currently open drawer views by animating them out of view.
Link copied to clipboard
open fun computeScroll()
Link copied to clipboard
Link copied to clipboard
The base elevation of the drawer(s) relative to the parent, in pixels.
Link copied to clipboard
open fun getDrawerLockMode(@NonNull drawerView: View): Int
Check the lock mode of the given drawer view.
open fun getDrawerLockMode(edgeGravity: Int): Int
Check the lock mode of the drawer with the given gravity.
Link copied to clipboard
open fun getDrawerTitle(edgeGravity: Int): CharSequence
Returns the title of the drawer with the given gravity.
Link copied to clipboard
Gets the drawable used to draw in the insets area for the status bar.
Link copied to clipboard
open fun isDrawerOpen(@NonNull drawer: View): Boolean
open fun isDrawerOpen(drawerGravity: Int): Boolean
Check if the given drawer view is currently in an open state.
Link copied to clipboard
open fun isDrawerVisible(@NonNull drawer: View): Boolean
open fun isDrawerVisible(drawerGravity: Int): Boolean
Check if a given drawer view is currently visible on-screen.
Link copied to clipboard
open fun isOpen(): Boolean
Check if the START drawer is currently in an open state.
Link copied to clipboard
open fun onDraw(@NonNull c: Canvas)
Link copied to clipboard
Link copied to clipboard
open fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean
Link copied to clipboard
open fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean
Link copied to clipboard
open fun onRtlPropertiesChanged(layoutDirection: Int)
Link copied to clipboard
Link copied to clipboard
open fun open()
Open the START drawer by animating it into view.
Link copied to clipboard
open fun openDrawer(@NonNull drawerView: View)
Open the specified drawer view by animating it into view.
open fun openDrawer(gravity: Int)
Open the specified drawer by animating it out of view.
open fun openDrawer(@NonNull drawerView: View, animate: Boolean)
Open the specified drawer view.
open fun openDrawer(gravity: Int, animate: Boolean)
Open the specified drawer.
Link copied to clipboard
Removes the specified listener from the list of listeners that will be notified of drawer events.
Link copied to clipboard
open fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean)
Link copied to clipboard
open fun requestLayout()
Link copied to clipboard
open fun seslSetContentView(view: View)
Link copied to clipboard
open fun seslSetTouchSensitivity(sensitivity: Float)
Link copied to clipboard
with fitsSystemWindows="true"
Link copied to clipboard
open fun setDrawerElevation(elevation: Float)
Sets the base elevation of the drawer(s) relative to the parent, in pixels.
Link copied to clipboard
Set a listener to be notified of drawer events.
Link copied to clipboard
open fun setDrawerLockMode(lockMode: Int)
Enable or disable interaction with all drawers.
open fun setDrawerLockMode(lockMode: Int, @NonNull drawerView: View)
open fun setDrawerLockMode(lockMode: Int, edgeGravity: Int)
Enable or disable interaction with the given drawer.
Link copied to clipboard
open fun setDrawerShadow(@Nullable shadowDrawable: Drawable, gravity: Int)
open fun setDrawerShadow(@DrawableRes resId: Int, gravity: Int)
Set a simple drawable used for the left or right shadow.
Link copied to clipboard
open fun setDrawerTitle(edgeGravity: Int, @Nullable title: CharSequence)
Sets the title of the drawer with the given gravity.
Link copied to clipboard
open fun setScrimColor(@ColorInt color: Int)
Set a color to use for the scrim that obscures primary content while a drawer is open.
Link copied to clipboard
open fun setStatusBarBackground(resId: Int)
Set a drawable to draw in the insets area for the status bar.
Link copied to clipboard
Set a drawable to draw in the insets area for the status bar.