片段上的变化而改变颜色状态栏[Android的棒棒糖] [英] Change statusbar color on Fragment change [Android Lollipop]

查看:206
本文介绍了片段上的变化而改变颜色状态栏[Android的棒棒糖]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何更改状态栏的颜色取决于当前的活性片段(上5.0棒棒堂)。目前,我改变动作条的颜色取决于我在片段,但现在我想的状态栏的颜色改变,以及 - 为了好看的棒棒糖设备。

I'm wondering how to change the StatusBar color dependent on the current active Fragment (on 5.0 Lollipop). Currently, I change the ActionBar color dependent on the Fragment I am in, but now I want the StatusBar color to change as well - in order to look nice on Lollipop devices.

我使用的setStyle以编程方式更改取决于片段主题试过,但它似乎并没有被改变状态栏的颜色。

I've tried using setStyle to programmatically change the theme depending on the fragment, but it doesn't seem to be changing the status bar color.

任何想法,将AP preciated!

Any ideas would be appreciated!

推荐答案

您是否尝试过更改使用 Window.setStatusBarColor 状态栏的颜色?例如,你可以做以下到状态栏的颜色变为红色编程。

Have you tried to change the color of the status bar using Window.setStatusBarColor? For example, you can do the following to change the status bar color to red programmatically.

getWindow().setStatusBarColor(Color.RED);

setStatusBarColor 的文件可以发现<一个href=\"https://developer.android.com/reference/android/view/Window.html#setStatusBarColor(int)\">here.您还可以阅读有关如何自定义状态栏的文档。

The documentation of setStatusBarColor can be found here. You can also read the documentation on how to Customize the Status Bar.

注意:此方法仅适用于棒棒糖或以上。

Note: This method only works at Lollipop or above.

如果你看到一个意想不到的颜色,请确保您传递的整数值是一个的色彩整数的,而不是一个资源ID。

If you are seeing an unexpected color, make sure the integer value you are passing is a color integer and not a resource ID.

getWindow().setStatusBarColor(getResources().getColor(R.color.custom_color)); // RIGHT
getWindow().setStatusBarColor(R.color.custom_color); // WRONG

这篇关于片段上的变化而改变颜色状态栏[Android的棒棒糖]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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