View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN not working

4.5k Views Asked by At

I want to make a completely transparent status bar and content behind it.

My device runs with 24 API.

I use this code (in my AppCompatActivity):

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    setContentView(R.layout.activity_main);


}

but it doesn't make any effect, my content is still UNDER the status bar; I also tried to put android:fitsSystemWindows="true" in my root view, but it didn't help either. I also tried to put the code after setContentView, still no effect.

What am I doing wrong?

2

There are 2 best solutions below

0
On

replace this with your code :

if (Build.VERSION.SDK_INT < 19)
{
   View v = this.getWindow().getDecorView();
   v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
   View decorView = getWindow().getDecorView();
   decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                    | View.SYSTEM_UI_FLAG_FULSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
0
On

Use this function callFullScreen

public void callFullScreen(Activity activity)
{
    activity.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);
}

You can remove some lines to get required result, and finally call callFullScreen(); inside onCreate