Reputation: 377
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)
Upvotes: 3
Views: 6439
Reputation: 516
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>
Upvotes: 0
Reputation: 3398
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
Upvotes: 2