3

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)

John
  • 377
  • 3
  • 14

3 Answers3

2

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

John
  • 377
  • 3
  • 14
Abhishek
  • 3,348
  • 3
  • 15
  • 34
  • setting the alpha to 0 still provides a shadow. I guess one option is to make both status and navigation bar transparent and add bar with color where the nav bar should go. But it seems cheap – John Sep 07 '17 at 08:03
  • when you set alpha to 0 it shows window background colour by default its white (window background changes as per parent theme). – Abhishek Sep 07 '17 at 08:06
  • Oh, yea you're right. I had fitSystemWindows on and I hadn't seen that flag you added, thought it was another one. Thanks! – John Sep 07 '17 at 08:13
  • what the hell... doesn't work anymore. Not sure what happened. will report back if fixed – John Sep 09 '17 at 04:43
  • @John check the theme which you are applying. If you applied other theme to other activity then again you have to make these changes. I think it should work – Abhishek Sep 09 '17 at 04:46
  • I'm gonna assume that it was just android studio 3.0. Damn I wanted a pure XML solution but I need to add *getWindow().getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);* but the previews don't look the same as runtime – John Sep 09 '17 at 05:49
  • Try to use it in your onCreate not in xml. – Abhishek Sep 15 '17 at 10:07
0

use this hex colour #00000000 in status bar

Vijay Chaudhary
  • 228
  • 2
  • 12
0

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>
whereismaxmax
  • 496
  • 5
  • 17