问题
I'm looking into a way where the status bar is completely transparent, not translucent and where the Navigation Bar is left untouched.
Closest I can get is to use the flag
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
but this draws behind the Navigation Bar as well.
The background is what is making this tricky, it is a subtle gradient, and when I set the status bar color to the start of the gradient, it looks almost right, but has a subtle line across the top of the screen.
Is there a good way to fit the activity to the window, only at the top but if there is a navigation bar at the bottom, leave it alone?
回答1:
A good approach is Method One from this answer.
To achieve a completely transparent status bar, you have to use statusBarColor, which is only available on API 21 and above. windowTranslucentStatus is available on API 19 and above, but it adds a tinted background for the status bar. However, setting windowTranslucentStatus does achieve one thing that changing statusBarColor to transparent does not: it sets the SYSTEM_UI_FLAG_LAYOUT_STABLE and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN flags. The easiest way to get the same effect is to manually set these flags, which effectively disables the insets imposed by the Android layout system and leaves you to fend for yourself.
You call this line in your onCreate method:
getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Be sure to also set the transparency in /res/values-v21/styles.xml:
<item name="android:statusBarColor">@android:color/transparent</item>
Or set the transparency programmatically:
getWindow().setStatusBarColor(Color.TRANSPARENT);
The good side to this approach is that the same layouts and designs can also be used on API 19 by trading out the transparent status bar for the tinted translucent status bar.
<item name="android:windowTranslucentStatus">true</item>
I'm guessing you've tried this or something similar. If that's not working, make sure your root element is a FrameLayout
.
来源:https://stackoverflow.com/questions/33354791/android-draw-behind-status-bar-but-not-behind-the-navigation-bar