Immersive Mode showing blank space

Try this:

override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)
    var viewParent = view
    while (viewParent is View) {
        viewParent.fitsSystemWindows = false
        viewParent.setOnApplyWindowInsetsListener { _, insets -> insets }
        viewParent = viewParent.parent as View?
    }
}

What does this do? DialogFragment#onActivityCreated() calls Dialog#setContentView(), which wraps the Dialog's view in a private 'wrapInBottomSheet'. In order to set the proper flags of those wrapper views, we want to set the flags after they are wrapped, e.g. after super.onActivityCreated()

Also watch this talk for info on fitsSystemWindows and window insets.


I'm new here so I can't comment, but wanted to add something that got me so frustrated me about the above solution. I kept checking my activities and its fragments for android:fitsSystemWindows="true" and it was definitely not there, yet I kept having a gap at the bottom! I was going nuts! It couldn't be this hard to fix this simple thing!

Turns out it also showed up in the Navigation Drawer I added...so be sure to check all your XML!


Please check that you don't have android:fitsSystemWindows="true" in your layout.

At least it solved my case - I had fitsSystemWindows on FrameLayout.