5

I am trying to implement Immersive (Fullscreen) Mode in my Android Application, and I'm running into a problem that I cannot solve.

I'm following the Immersive Mode guide and sample apps from the Android Docs, and it mostly works, but when exiting from Immersive Mode, the App Bar (Action Bar) on my app remains in Overlay mode (it does not start in overlay mode when the activity launches), thus obscuring some of the content of my activity, and I cannot figure out what combination of UI Flags and bitwise operators I need to supply to setSystemUiVisibility() when exiting Immersive Mode to get it to put my app back in it's initial state (with an App Bar that's not in Overlay mode).

I have a demo application that shows the problem, and relative code bits are as follows:

Styled using the built in toolbar/app bar/action bar, though I have tried using my own custom toolbar and setting it as the Support Action Bar, with the same results.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

Clicking the "Toggle Immersive Mode" button in the activity runs the following method, which follows the Android Guide (see link above) for Immersive Mode.

private void toggleImmersiveMode() {
    View decorView = getWindow().getDecorView();

    if (mIsImmersiveEnabled) {
        // Immersive Mode is on, turn it off.
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
              | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    } else {
        // Immersive Mode is off, turn it on.
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE
                // Set the content to appear under the system bars so that the
                // content doesn't resize when the system bars hide and show.
              | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
              | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                // Hide the nav bar and status bar
              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }

    mIsImmersiveEnabled = !mIsImmersiveEnabled;

}

I'm not trying to disable the app bar from going into Overlay Mode when ENTERING immersive mode (I want that functionality), but I can't figure out how to get it to turn overlay mode back off when EXITING immersive mode. Any help would be appreciated.

here are some screenshots of the demo app:

On Initial Launch

initial launch

After Entering Fullscreen Mode

Fullscreen Mode

After Exiting Fullscreen Mode

After Exit Fullscreen

Mauker
  • 11,237
  • 7
  • 58
  • 76
Bradleycorn
  • 980
  • 6
  • 9
  • Just a thought: Have you tried to replace your ActionBar with a Toolbar? – Mauker May 15 '18 at 16:42
  • I have replaced the style with a `NoActionBar` style, added my own Toolbar in the layout, and then used `setSupportActionBar(mToolbar)` to set my toolbar as the action bar, and I get the same results. I have not tried eliminating the action bar all together. I suspect that would work (as the toolbar would be just another part of the activity's layout), but I need/want the actionbar for the application I'm working on. – Bradleycorn May 15 '18 at 18:39
  • If you use a custom toolbar and then constrain your textview to the bottom of it, does that help? – CKP78 Oct 03 '18 at 11:31

0 Answers0