Overlap a Transparent Status Bar

There’s a lot going on about making your Status Bar transparent for your Activities. But most of the time, its easier said than done and if android:fitsSystemWindows = "true" doesn’t work for you, then there is another way.

Add this before your setContentView()

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            getWindow().setStatusBarColor(getResources().getColor(R.color.black_trans80,null));

}

Remember that a transparent Status Bar works only on Lollipop and above. For Android KitKat 4.4 it is translucent. Android Jelly Bean 4.2 and below, it remains black and there’s nothing you can do about that.

The Status Bar color here could be anything, but as per norms it must be 20% opacity black.

NOTE: Don’t forget to add a 24dp padding to your Toolbar top, since it will now be under the Status Bar.

Suleiman

Product Designer who occasionally writes code.

Leave a Reply

Your email address will not be published. Required fields are marked *