Android 5.0 上的 Android 4.4 半透明状态和导航栏样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26474125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android 4.4 translucent Status and Navigation bars style on Android 5.0
提问by AxeEffect
On Android 4.4 KitKat you can set the Status and Navigation bars transparent with the android:windowTranslucentStatus
and android:windowTranslucentNavigation
theme elements, and then below the bars the app window is extended and a gradient is added. However on Android 5.0 Lollipop this has been changed and now instead of the gradient a solid transparent color is added. Android 5.0 offers the new android:statusBarColor
and android:navigationBarColor
elements under the new Material theme, but when you try to set these elements to @android:color/transparent
the app window is not extended, and if you use android:windowTranslucentStatus
and android:windowTranslucentNavigation
then android:statusBarColor
and android:navigationBarColor
are ignored.
在 Android 4.4 KitKat 上,您可以使用android:windowTranslucentStatus
和android:windowTranslucentNavigation
主题元素将状态栏和导航栏设置为透明,然后在栏下方扩展应用程序窗口并添加渐变。然而,在 Android 5.0 Lollipop 上,这已被更改,现在添加了纯透明颜色而不是渐变。Android 5.0在新的Material 主题下提供了new android:statusBarColor
andandroid:navigationBarColor
元素,但是当你尝试将这些元素设置到@android:color/transparent
app 窗口时是不会扩展的,如果你使用android:windowTranslucentStatus
and android:windowTranslucentNavigation
then android:statusBarColor
and 都会android:navigationBarColor
被忽略。
Am I missing something described on http://developer.android.com/training/material/theme.html#StatusBar?
我是否遗漏了http://developer.android.com/training/material/theme.html#StatusBar 上描述的内容?
回答by suckgamony
Set android:windowTranslucentStatus
to falseand set android:statusBarColor
to @android:color/transparent
.
设置android:windowTranslucentStatus
为false并设置android:statusBarColor
为@android:color/transparent
。
Then add code below:
然后在下面添加代码:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
If you also want the navigation bar to be translucent, set android:navigationBarColor
to @android:color/transparent
and combine the flag View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
as well.
如果您还希望导航栏是半透明的,也可以设置android:navigationBarColor
为@android:color/transparent
并组合标志View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
。
I didn't experiment on the navigation bar but it will work.
我没有在导航栏上进行实验,但它会起作用。
回答by Kuldeep Sakhiya
Add below line to your style:
将以下行添加到您的样式中:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
回答by CODE-REaD
To clarify @suckgamony's answerto this question:
澄清@suckgamony对这个问题的回答:
- Under Lollipop and above, setting
android:statusBarColor
orandroid:navigationBarColor
to@android:color/transparent
will make the Status Baror Navigation Bar(respectively) completely transparent, unless: android:windowTranslucentStatus
orandroid:windowTranslucentNavigation
is set to true, in which case the Status Baror Navigation Bar(respectively) is set to the solid transparent color @AxeEffect describes (again, under Lollipop and above);android:statusBarColor
andandroid:navigationBarColor
may only be used with Android version 21 (Lollipop 5.0) or higher. As described in the referred to answer,android:windowTranslucentStatus
orandroid:windowTranslucentNavigation
when used with Kitkat provide transparent gradients rather than full transparency.
- 下棒棒糖和上面,设置
android:statusBarColor
或android:navigationBarColor
以@android:color/transparent
将使状态栏或导航栏(分别)是完全透明的,除非: android:windowTranslucentStatus
或android:windowTranslucentNavigation
设置为 true,在这种情况下,状态栏或导航栏(分别)设置为@AxeEffect 描述的纯透明颜色(同样,在 Lollipop 及以上);android:statusBarColor
并且android:navigationBarColor
只能与 Android 版本 21 (Lollipop 5.0) 或更高版本一起使用。如参考答案中所述,android:windowTranslucentStatus
或android:windowTranslucentNavigation
与 Kitkat 一起使用时提供透明渐变而不是完全透明。