# Bottom Sheets [Bottom sheets](https://material.io/components/sheets-bottom) are surfaces containing supplementary content that are anchored to the bottom of the screen. ![Example bottom sheet: modal bottom sheet](assets/bottomsheet/bottomsheet_hero.png) **Contents** * [Design & API Documentation](#design-api-documentation) * [Using bottom sheets](#using-bottom-sheets) * [Standard bottom sheet](#standard-bottom-sheet) * [Modal bottom sheet](#modal-bottom-sheet) * [Anatomy and key properties](#anatomy-and-key-properties) * [Predictive Back](#predictive-back) * [Theming](#theming-bottom-sheets) ## Design & API Documentation * [Google Material3 Spec](https://material.io/components/bottom-sheets/overview) * [API Reference](https://developer.android.com/reference/com/google/android/material/bottomsheet/package-summary) ## Using bottom sheets Before you can use Material bottom sheets, you need to add a dependency to the Material Components for Android library. For more information, go to the [Getting started](https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md) page. Standard bottom sheet basic usage: ```xml ``` Modal bottom sheet basic usage: ```kt class ModalBottomSheet : BottomSheetDialogFragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? = inflater.inflate(R.layout.modal_bottom_sheet_content, container, false) companion object { const val TAG = "ModalBottomSheet" } } class MainActivity : AppCompatActivity() { ... val modalBottomSheet = ModalBottomSheet() modalBottomSheet.show(supportFragmentManager, ModalBottomSheet.TAG) ... } ``` More information on each individual section, below. ### Setting behavior There are several attributes that can be used to adjust the behavior of both standard and modal bottom sheets. Behavior attributes can be applied to standard bottom sheets in xml by setting them on a child `View` set to `app:layout_behavior`, or programmatically: ```kt val standardBottomSheetBehavior = BottomSheetBehavior.from(standardBottomSheet) // Use this to programmatically apply behavior attributes ``` Behavior attributes can be applied to modal bottom sheets using app-level theme attributes and styles: ```xml ``` Or programmatically: ```kt val modalBottomSheetBehavior = (modalBottomSheet.dialog as BottomSheetDialog).behavior // Use this to programmatically apply behavior attributes ``` More information about these attributes and their default values is available in the [behavior attributes](#behavior-attributes) section. ### Retaining behavior on configuration change In order to save and restore specific behaviors of the bottom sheet on configuration change, the following flags can be set (or combined with bitwise OR operations): * `SAVE_PEEK_HEIGHT`: `app:behavior_peekHeight` is preserved. * `SAVE_HIDEABLE`: `app:behavior_hideable` is preserved. * `SAVE_SKIP_COLLAPSED`: `app:behavior_skipCollapsed` is preserved. * `SAVE_FIT_TO_CONTENTS`: `app:behavior_fitToContents` is preserved. * `SAVE_ALL`: All aforementioned attributes are preserved. * `SAVE_NONE`: No attribute is preserved. This is the default value. Behaviors can also be set in code: ```kt bottomSheetBehavior.saveFlags = BottomSheetBehavior.SAVE_ALL ``` Or in xml using the `app:behavior_saveFlags` attribute. ### Setting state Standard and modal bottom sheets have the following states: * `STATE_COLLAPSED`: The bottom sheet is visible but only showing its peek height. This state is usually the 'resting position' of a bottom sheet, and should have enough height to indicate there is extra content for the user to interact with. * `STATE_EXPANDED`: The bottom sheet is visible at its maximum height and it is neither dragging nor settling (see below). * `STATE_HALF_EXPANDED`: The bottom sheet is half-expanded (only applicable if `behavior_fitToContents` has been set to false), and is neither dragging nor settling (see below). * `STATE_HIDDEN`: The bottom sheet is no longer visible and can only be re-shown programmatically. * `STATE_DRAGGING`: The user is actively dragging the bottom sheet up or down. * `STATE_SETTLING`: The bottom sheet is settling to a specific height after a drag/swipe gesture. This will be the peek height, expanded height, or 0, in case the user action caused the bottom sheet to hide. You can set a state on the bottom sheet: ```kt bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED ``` **Note:** `STATE_SETTLING` and `STATE_DRAGGING` should not be set programmatically. ### Listening to state and slide changes A `BottomSheetCallback` can be added to a `BottomSheetBehavior`: ```kt val bottomSheetCallback = object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(bottomSheet: View, newState: Int) { // Do something for new state. } override fun onSlide(bottomSheet: View, slideOffset: Float) { // Do something for slide offset. } } // To add the callback: bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallback) // To remove the callback: bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallback) ``` ### Handling insets and fullscreen `BottomSheetBehavior` can automatically handle insets (such as for [edge to edge](https://developer.android.com/training/gestures/edge-to-edge)) by specifying any of these to true on the view: * `app:paddingBottomSystemWindowInsets` * `app:paddingLeftSystemWindowInsets` * `app:paddingRightSystemWindowInsets` * `app:paddingTopSystemWindowInsets` On API 21 and above the modal bottom sheet will be rendered fullscreen (edge to edge) if the navigation bar is transparent and `app:enableEdgeToEdge` is true. To enable edge-to-edge by default for modal bottom sheets, you can override `?attr/bottomSheetDialogTheme` like the below example: ``` ``` Insets can be added automatically if any of the padding attributes above are set to true in the style, either by updating the style passed to the constructor, or by updating the default style specified by the `?attr/bottomSheetDialogTheme` attribute in your theme. `BottomSheetDialog` will also add padding to the top when the bottom sheet slides under the status bar, to prevent content from being drawn underneath it. ### Making bottom sheets accessible The contents within a bottom sheet should follow their own accessibility guidelines, such as setting content descriptions for images. To support dragging bottom sheets with accessibility services such as TalkBack, Voice Access, Switch Access, etc., we provide a convenient widget `BottomSheetDragHandleView` which will automatically receive and handle accessibility commands to expand and collapse the attached bottom sheet when the accessibility mode is enabled. To use `BottomSheetDragHandleView`, you can add it to the top of your bottom sheet content. It will show a customizable visual indicator for all users. See the example in the below section for how to add a drag handle to your bottom sheet. **Note:** `BottomSheetDragHandleView` has a default min width and height of 48dp to conform to the minimum touch target requirement. So you will need to preserve at least 48dp at the top to place a drag handle. ## Standard bottom sheet Standard bottom sheets co-exist with the screen’s main UI region and allow for simultaneously viewing and interacting with both regions. They are commonly used to keep a feature or secondary content visible on screen when content in the main UI region is frequently scrolled or panned. [`BottomSheetBehavior`](https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetBehavior) is applied to a child of [CoordinatorLayout](https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout) to make that child a **persistent bottom sheet**, which is a view that comes up from the bottom of the screen, elevated over the main content. It can be dragged vertically to expose more or less content. API and source code: * `BottomSheetBehavior` * [Class definition](https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetBehavior) * [Class source](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java) ### Standard bottom sheet example The following example shows a standard bottom sheet in its collapsed and expanded states: Collapsed | Expanded ----------------------------------------------------------------------------------------- | -------- ![Standard collapsed bottom sheet example.](assets/bottomsheet/bottomsheet_standard1.png) | ![Standard expanded bottom sheet example.](assets/bottomsheet/bottomsheet_standard2.png) `BottomSheetBehavior` works in tandem with `CoordinatorLayout` to let you display content on a bottom sheet, perform enter/exit animations, respond to dragging/swiping gestures, etc. Apply the `BottomSheetBehavior` to a direct child `View` of `CoordinatorLayout`: ```xml