Immersive Mode showing blank space

后端 未结 5 1223
孤独总比滥情好
孤独总比滥情好 2020-12-29 05:48

I\'m trying to implement a fullscreen mode, but for Android 4.4 and up, it shows a blank space there:

BEFORE immersive mode(fullscreen)

相关标签:
5条回答
  • 2020-12-29 05:57

    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!

    0 讨论(0)
  • 2020-12-29 06:06

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

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

    0 讨论(0)
  • 2020-12-29 06:11

    Just change the android:fitsSystemWindows="true" to android:fitsSystemWindows="false" in your layout file.

    0 讨论(0)
  • 2020-12-29 06:18

    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.

    0 讨论(0)
  • 2020-12-29 06:24

    You need to add this flag to your view View.SYSTEM_UI_FLAG_LAYOUT_STABLE. Try it like this

    // This snippet hides the system bars.
    private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
    }
    
    // This snippet shows the system bars. It does this by removing all the  flags
    // except for the ones that make the content appear under the system bars.
    private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    
    0 讨论(0)
提交回复
热议问题