Status bar transparency does not work

I am trying to make the status bar transparent in my application using this code:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().setStatusBarColor(Color.TRANSPARENT); 

But that will not work. The status bar just changes color and turns gray, not transparent. Where is my mistake? How to make the status bar transparent?

+6
source share
2 answers

Try this in styles.xml(v21)

 <name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:windowTranslucentStatus">true</item> 

Update

You can achieve the same effect programmatically on KitKat, and then check this box in the window.

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); // in Activity onCreate() for instance w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } 

If you set a background resource (for example, color or image) to the layout, you will see the color or image โ€œbelowโ€ in the status bar.

 <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@color/primary_dark</item> 

A source

+4
source

try calling this from onCreate:

 getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); getWindow().setStatusBarColor(Color.TRANSPARENT); 
+1
source

All Articles