Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent the Nav Bar from leaving behind a black bar? (immersive mode)

An app that uses immersive mode leaves a black bar at the bottom of the screen when the app is returned to after waiting a while (activity is destroyed).

What is happening: (I have enabled the developer option: "Don't keep activities" to reproduce this).

  1. First time launch of the app. Immersive mode works as expected.

  2. Swipe up to reveal the 'immersive sticky' nav bar, and use the 'Home' button to leave the app. The background of the nav bar briefly shows a black background before the app closes.

  3. Use the 'Recents' button, and select the app to resume it.

  4. The app opens to briefly reveal the nav bar over a black bar. The system ui collapses into immersive mode but the black bar remains. systemuiblackbar

This bug also only appears on Lollipop, not KitKat.

I have stripped back the app to simply launching a dummy activity with no functionality apart from setting System UI flags:

public class DummyActivity extends FragmentActivity {

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        setSystemUiVisibility();
    }
}

public void setSystemUiVisibility() {
    if (getWindow() != null && getWindow().getDecorView() != null) {
        getWindow().getDecorView().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
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}

EDIT: After creating a new fresh project with only this Activity I have seen this issue reproduced when using an app theme extending "android:Theme.Holo"..., and fixed the issue in this sample project when I extend the Material theme instead:

Change

<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>

to

<style name="AppTheme"parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
</style>

Unfortunately this fix hasn't solved the issues in my main project, but it brings me closer to a solution and might help others with the same issue.

like image 233
ITJscott Avatar asked Feb 24 '15 18:02

ITJscott


1 Answers

I was having the same problem. Here are a few updates I made which made it go away. Hopefully one of these works for you!

activity_main.xml

android:fitsSystemWindows="false"

style-v21

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowSharedElementsUseOverlay">false</item>

MainActivity.java

getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
    );
like image 196
Nick Avatar answered Sep 27 '22 18:09

Nick