I want to have a transparent status bar on my app (so the background goes behind it) but I want the navigation bar at the bottom to stay black.
I can make both transparent by setting getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
I can make the top translucent (partially transparent) by setting <item name="android:windowTranslucentStatus">true</item>
However, I can't make the top completely transparent without making the bottom transparent too. Using <item name="android:statusBarColor">@android:color/transparent</item>
or similar doesn't work.
Does anyone know how to make a fully transparent status bar without affecting the navigation bar?
Best Answer
To independently control the transluscency of the status and navigation bars on KitKat, you can simply use the window manager flags
FLAG_TRANSLUSCENT_STATUS
andFLAG_TRANSLUSCENT_NAVIGATION
in theonCreate()
method of your activity. However, on KitKat the system may draw a semi-opaque gradient scrim drawable over the status bar. This appears to be device-specific: on my KitKat device it's fully transparent, but on Android Studio emulator it shows a scrim.On Lolliop or later you can instead set the status bar colour using the
Window#setStatusBarColor(int)
method together with theFLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
window manager flag. Note that you clear theFLAG_TRANSLUSCENT_STATUS
flag in this case. If you want the colour to be transparent, that implies that your application supports full screen mode and sets the system UI visibility, so it's down to your app to manage the status bar background colour.Putting it all together would look something like this:
Example of layout used:
Example screenshots.
Lollipop:
KitKat: