---
title: "Advanced Android Edge-to-Edge (Part 2): BottomSheetDialogFragment"
source: "/writing/advanced-android-edge-to-edge-part-2-bottomsheetdialogfragment/"
---

Article

# Advanced Android Edge-to-Edge (Part 2): BottomSheetDialogFragment

Alex Vanyo

February 5, 2021

API 29 with Gesture Navigation

This is the second part of a series devoted to providing complete working examples of advanced use cases for insets on Android. The snippets in these posts can be found in context at [https://github.com/alexvanyo/android-edge2edge](https://github.com/alexvanyo/android-edge2edge) .

-   [Part 1: Responding to keyboard transitions with](/writing/advanced-android-edge-to-edge-part-1-keyboard-transitions-with-motionlayout) `[MotionLayout](/writing/advanced-android-edge-to-edge-part-1-keyboard-transitions-with-motionlayout)`
-   [Part 2: Insets and](#id-1) `[BottomSheetDialogFragment](#id-1)`
-   Part 3: Mind your horizontal insets (coming soon!)

## Part 2: Making BottomSheetDialogFragment go edge-to-edge

[Bottom sheets](https://material.io/components/sheets-bottom) are a very common material design component, often used for context menus or to present the user with a larger menu of choices. Like their name suggests, bottom sheets appear on the bottom of the screen, which (usually) means that they must interact with the navigation bar. Google's provided implementation for a bottom sheet, `BottomSheetDialogFragment` (as of `1.2.x` and the `1.3.x` versions*) interaction is passable, but not ideal for an app that wants to go fully edge-to-edge:

Default behavior with API 29 with Gesture Navigation

The navigation bar is translucent, and since the content behind the bottom sheet is fully edge-to-edge, you can awkwardly see some of it below the bottom of the sheet!

`BottomSheetDialogFragment` achieves its inset handling with `[fitsSystemWindows = true](https://github.com/material-components/material-components-android/blob/3eddfb99c8516f4e664eeff88740660b12691934/lib/java/com/google/android/material/bottomsheet/res/layout/design_bottom_sheet_dialog.xml#L24)` , which is unfortunately the enemy of having total control over the insets.

The solution to this is to modify the layout that `BottomSheetDialog` wraps around our layout, and also set `decorFitsSystemWindows` to `false` on the dialog's window:

By setting `fitsSystemWindows` to `false` for both the internal `container` and the `coordinator`, we can now handle the insets directly as desired, such as padding for `RecyclerView`s, or margins for other views.

The last step is a bit of styling, to provide a transparent navigation bar on older APIs:

Putting it all together, here is the final result across API 29 with and without gesture navigation, as well as on API 24:

API 29 with Gesture Navigation

API 29 with 3 Button Navigation

API 24

*The latest primary branch of [https://github.com/material-components/material-components-android](https://github.com/material-components/material-components-android) has new built-in support for insets, but has yet to be released. I'll update this article with the new approach once it has been released.

Thanks for reading! For more detail, the full sample application can be found at [https://github.com/alexvanyo/android-edge2edge](https://github.com/alexvanyo/android-edge2edge) . If you haven't already, be sure to check out the first article for handling keyboard animations with `MotionLayout:`

[Advanced Android Edge-to-Edge (Part 1): Keyboard Transitions with MotionLayout](/writing/advanced-android-edge-to-edge-part-1-keyboard-transitions-with-motionlayout-66ae34d4c78a?source=post_page-----f6d7b62aeb1c-------------------------------) _Alex applies insets at_ [_Livefront_](https://livefront.com/) _so that apps can look their best from all edges._

-   Alex Vanyo

    Software Engineer

    Alex Vanyo

### Tags

[Digital Engineering](/insights/all/?topic=digital-engineering) [Mobile Apps](/insights/all/?topic=mobile-apps)

### Share

-   Copied

## View these next.

[See all](/insights/all/?type=writing)

-   [

    Article

    How To Sabotage Your Project Using Inconsistency

    Collin Flynn

    ](/writing/how-to-sabotage-your-project-using-inconsistency/)
-   [

    Article

    Unit Testing race conditions by creating chaos (Swift)

    Sean Berry

    ](/writing/unit-testing-race-conditions-by-creating-chaos-swift/)
-   [

    Article

    UIApplicationDelegate call sequence reference

    Sean Berry

    ](/writing/uiapplicationdelegate-call-sequence-reference/)
