Search code examples
javaandroidandroid-studioandroid-statusbar

Making status bar fully transparent on Android 11+


I want to make the app statusBar fully transparent. I used WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS

It's making statusBar as I want. But it also makes the navigation bar on Top of my content. I used many methods to make the navigation bar not change but failed. There are many answers on the internet, but nothing works. How to make a full transparent statusBar without black shadow and without navigationBar change?


Solution

  • I wasn't helped by anybody by making the question. But after some month, when making another app, I got the answer of this question and it just worked with my app.

    getSupportActionBar().hide();
    
    
        if (Build.VERSION.SDK_INT >= 21) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= 19) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //Virtual keyboard is also transparent
            //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    

    I hope this code will work fine!