androidlayoutandroid-immersive

When Android automatically exits Immersive Sticky it does not resize views so they are blocked


I have an activity which can go to Immersive Sticky Full Screen on the click of the button. This button does the following code in order to get into Immersive Sticky Full Screen.

getActivity().getWindow().getDecorView().setSystemUiVisibility(
      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);

Note: I specifically do NOT include the following tag as if I do, it breaks the layout of my screen when I exit Immersive Sticky Full Screen.See my other question: Android closing full screen view at the bottom is shunted off the screen

View.SYSTEM_UI_FLAG_LAYOUT_STABLE

When Android is in Immersive Sticky Full Screen when another view is displayed, such as a DialogFragment, a AlertDialog, keyboard comes up, Android automatically takes you out of Immersive Sticky Full Screen by showing the Status Bar and on screen navigation bar. However it does NOT resize the views in my application, so now my views are underneath the navigation bar and I can not get to any of the buttons at the bottom of my screen. I have tested with the "View.SYSTEM_UI_FLAG_LAYOUT_STABLE" flag and it makes no difference, the views are still not resized.

This seems a massive flaw in Android's behavior and surely I am doing something wrong. How can I get it to resize my views when it displays the status bar and Navigation bar?

I can work around some cases, such as Dialogs popping up by using the code in the following SO question, https://stackoverflow.com/a/24549869/2663916 but I have lots of possible things that could popup on my full screen view and I don't want to have to put that hack in every single place to keep it in immersive full screen. Furthermore, when the keyboard comes up I DO want the navigation bar to appear.

Surely Android should adjust the on screen views when it is displaying the on screen bars.


Solution

  • Re-reading Google docs made it obvious that the cause was the inclusion of the following two flags

    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN      // this STOPS Android resizing my view to be below the status bar when it is displayed
    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // this STOPS Android resizing my view to be above the nav bar when it is displayed
    

    https://developer.android.com/training/system-ui/immersive.html "It's good practice to include other system UI flags (such as SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION and SYSTEM_UI_FLAG_LAYOUT_STABLE) to keep the content from resizing when the system bars hide and show. You should also make sure that the action bar and other UI controls are hidden at the same time. "