Transparent Status bar android

6.4k views Asked by At

I tried

setting the statusBarColor to transparent, but it leaves a shadow

setting the windowTranslucentStatus to true, but it leaves a shadow

mixed and matched the above properties with fitsSystemWindow... no success

doing the following achieves the goal of completely transparent status... but also makes the nav bar completely transparent

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

How can I make only the status bar 100% transparent without touching the navBar

minSdk: 21

target: 26

compile 26

Android studio 3.0 preview (latest as of 9/6/17)

3

There are 3 answers

0
Vijay Chaudhary On

use this hex colour #00000000 in status bar

7
Abhishek On

I think you can't make status bar 100% transparent because activity has its own window background(default background is white you can set window background using getWindow().setBackgroundDrawableResource(int resID) or getWindow().setBackgroundDrawable(Drawable drawable))

You can set colour to status bar and set colour opacity in hex form after setContentView() shown in below code.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(Color.parseColor("#00FFFFFF"));
    }

//Here "#00FFFFFF" means opacity is 0% (first two digits 00) and colour is white (next FFFFFF character).

Or in styles.xml (post-Lollipop versions only. Compatibility may be compromised)

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

For setting opacity refer this link

0
whereismaxmax On

I just did the same under the same conditions

You right about FLAG_LAYOUT_NO_LIMITS, but it is the way (code in kotlin)

//onCreate
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
toolbar.setPadding(0, getStatusBarHeight(), 0, 0)

getStatusBarHeight:

private fun getStatusBarHeight(): Int {
    var result = 0
    val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
    if (resourceId > 0) {
        result = resources.getDimensionPixelSize(resourceId)
    }
    return result
}

and way how to return your navigation bar - put this in your styles:

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