如何将状态栏设置为透明,但导航栏保持黑色? [英] How do I set my status bar transparent but keep by navigation bar black?

查看:506
本文介绍了如何将状态栏设置为透明,但导航栏保持黑色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我的问题所暗示的,我试图弄清楚如何将状态栏颜色设置为透明,同时保持导航栏为黑色/自然色(不影响屏幕高度)
我提到了这个网站:



第二个视图是该视图在状态栏可以正常工作的上方添加了代码之后,屏幕又在下面滑动,使导航栏也变得透明(即使设置 fitsSystemWindows = false 也无济于事)。





谢谢!

解决方案

您需要在活动主题中添加以下样式。



styles.xml 中找到您活动的主题并添加以下内容。由于您的最低SDK版本为23,因此您无需担心Android的先前版本。

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

这是我所得到的屏幕截图。





这是我的主题样式我的情况。

 < style name = NoActionBar parent = Theme.AppCompat.NoActionBar> 
< item name = android:windowActionBar> false< / item>
< item name = android:windowNoTitle> true< / item>
< item name = android:windowDrawsSystemBarBackgrounds> false< / item>
< item name = android:windowTranslucentStatus> true< / item>
< / style>

希望能解决您的问题。


As my question suggests, I am trying to figure out how to set my status bar color transparent while keeping my navigation bar black/natural color (without affecting the screen height) I referred to this site : Android Completely transparent Status Bar? one of the solutions that partially worked was :

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

but that pushes my screen content below navigation bar making it transparent. I want the screen size to remain the same while keeping the navigation bar its natural color. Just want to make the status bar transparent, but seems like all other ways make it off-white even when I set it transparent with (setstatusbarcolor option).

Any ideas on how to go about it? My min SDK version is 23.

The second view is the view after adding the code above where the status bar works but the screen slides below making the nav bar transparent as well (even setting fitsSystemWindows = false doesn't help).

Thanks in advance!

解决方案

You need to add the following style in your activity theme.

In the styles.xml find the theme of your activity and add the following. As the minimum SDK version is 23 in your case, you do not need to worry about the previous versions of Android.

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

Here is the screenshot of what I have got.

Here's the theme style that I have in my case.

<style name="NoActionBar" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

Hope that solves your problem.

这篇关于如何将状态栏设置为透明,但导航栏保持黑色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆