更改状态栏的颜色与AppCompat ActionBarActivity [英] Change status bar color with AppCompat ActionBarActivity
问题描述
在我的一个活动我使用工具栏更改颜色调色板
,但使用 ActionBarActivity
的<$ C 5.0的设备$ C>状态栏颜色是我的 colorPrimaryDark
在我的活动主题的颜色,所以我有两个非常不同的颜色,它看起来并不好。
in my one Activity I change the Toolbar color using Palette
but on 5.0 devices using ActionBarActivity
the status bar
color is the color of my colorPrimaryDark
in my activity theme so I have 2 very different color and it does not look good.
我意识到,在5.0,您可以使用 Window.setStatusBarColor()
,但 ActionBarActivity
不具备这一点。
I realize that in 5.0 you can use Window.setStatusBarColor()
but ActionBarActivity
does not have this.
所以我的问题是在5.0如何更改状态栏的颜色与 ActionBarActivity
?
so my question is in 5.0 how can I change the status bar color with ActionBarActivity
?
推荐答案
我不知道我理解这个问题。
I'm not sure I understand the problem.
我要编程方式更改状态栏的颜色(和提供的设备有安卓5.0),那么您可以使用<一个href="https://developer.android.com/reference/android/view/Window.html#setStatusBarColor%28int%29"><$c$c>Window.setStatusBarColor()$c$c>.它不应该有所作为从活动
或 ActionBarActivity
。
I you want to change the status bar color programmatically (and provided the device has Android 5.0) then you can use Window.setStatusBarColor()
. It shouldn't make a difference whether the activity is derived from Activity
or ActionBarActivity
.
刚刚尝试做的:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.BLUE);
}
刚刚测试此与 ActionBarActivity
和它的作品好了。
注:设置 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
标志编程方式是没有必要的,如果你的值-V21
样式文件将其设置已经通过:
Note: Setting the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
flag programmatically is not necessary if your values-v21
styles file has it set already, via:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
这篇关于更改状态栏的颜色与AppCompat ActionBarActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!