androidandroid-fragmentsnavigationandroid-fullscreen

Set Fragment to FullScreen while using Navigation Component - Android


I recently converted my app to Single Activity architecture and trying to set the one particular fragment to fullscreen. The standard fullscreen code for activity does not work for fragments

final int flags =
            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
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

I found this Android set full screen from fragment. But settings it to FLAG_LAYOUT_NO_LIMITS causes the PagerSnapHelper in the fragment to jump around when switching between FLAG_LAYOUT_NO_LIMITS and revoking it.

So my question is, is there any other way to set fragment to fullscreen without using FLAG_LAYOUT_NO_LIMITS.


Solution

  • You shouldn't ever need to use FLAG_LAYOUT_NO_LIMITS, nor should you apply fitsSystemWindows="true" globally at your activity layer - that is what would prevent your fragment from going full screen. Instead, only add fitsSystemWindows on the fragments / individual components that would otherwise overlap the status/system bars. This would ensure that your full screen fragment would be able to take up the full size and not be inset from the edges.