状态栏颜色未显示 - 5.0 Lollipop Android Studio: (AppCompat-v7:r21) [英] Status Bar Color not showing - 5.0 Lollipop Android Studio: (AppCompat-v7:r21)

查看:21
本文介绍了状态栏颜色未显示 - 5.0 Lollipop Android Studio: (AppCompat-v7:r21)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android Studio 中为 Android 5.0 Lollipop 使用 AppCompat-v7:21.0.0 支持库.我的问题是,可以通过在 values/styles.xml 文件中设置 colorPrimaryDark 来更改的状态栏颜色在两个 xml 布局预览中都显示为黑色和模拟器.

I'm using the AppCompat-v7:21.0.0 support library for Android 5.0 Lollipop in Android Studio. My problem is that the Status Bar Color that can be changed by setting colorPrimaryDark in the values/styles.xml file, is showing up as black, in both the xml layout preview and the emulator.

怎么了?我错过了什么吗?请告诉我.谢谢.

So what's wrong? Am I missing something? Please let me know. Thanks.

我知道无法更改 Pre-Lollipop 版本上的状态栏颜色.我的 XML 布局编辑器预览和我的模拟器都设置为 API 级别 21 (5.0 Lollipop).但是,状态栏仍然不是我在 colorPrimaryDark 中设置的颜色.我尝试在 styles.xml 中做 statusBarColor 但无济于事.还是黑的.

I'm aware of the fact that changing the status bar color on Pre-Lollipop versions is not possible. My XML Layout Editor Preview and my Emulator are both set to API Level 21 (5.0 Lollipop). But, the status bar still isn't of the color I set it to in colorPrimaryDark. I tried doing statusBarColor in styles.xml but to no avail. It's still black.

还: 我看到了一个类似问题的答案,他们建议我将 minSdkVersion 设置为 21.我试过了,但没有不行.我希望我的应用能够在 API 级别 15 及更高级别的设备上运行.

ALSO: I saw one of the answers on a similar question where they advised me to put my minSdkVersion to 21. I tried that, but it didn't work. And I want my app to run on devices with API Level 15 and above.

推荐答案

请阅读:要使此生效,窗口必须用

Please read this: For this to take effect, the window must be drawing the system bar backgrounds with

android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS

但是

android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS

不得设置(来源)

如果您不知道如何添加该标志:

In case of you don't know how to add that flag:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

这篇关于状态栏颜色未显示 - 5.0 Lollipop Android Studio: (AppCompat-v7:r21)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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