Full screen + action bar (Immersive)
Asked Answered
S

2

14

Currently I am using low profile mode to hide the top black bar and dim the bottom nav bar. I want to use Immersive mode on Android but I'm having issues with the action bar. I would like to do Immersive mode sticky but keep the action bar where it should be. Is there no way to do this?

This is what I have so far and it works except that it hides the action bar as well.

@TargetApi(19)
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        if (android.os.Build.VERSION.SDK_INT >= 19) {
            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);
        }
    }
}

Any advice would be wonderful. Thank you.

Sauna answered 8/3, 2014 at 6:25 Comment(0)
C
17

I just tried this code on my nexus 7 (Android 4.4.2) and works fine

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        if (hasFocus) {
            decorView
                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}
Colangelo answered 21/3, 2014 at 14:1 Comment(1)
Yeah the culprit seemed to be View.SYSTEM_UI_FLAG_LAYOUT_STABLE. However now when I start a new activity, the bars go up (then back down). Is there a way to set these flags before starting the activity?Sauna
A
0

You can add this close in onResume event.

@Override
    public void onResume() {
        super.onResume();
        getWindow().getDecorView().setSystemUiVisibility(
                View.GONE);
    }
Aney answered 25/9, 2017 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.