如何更改状态栏颜色以棒棒堂匹配的应用程序? [机器人]机器人、应用程序、状态栏、棒棒

2023-09-12 21:55:05 作者:流泪的天使

在新的棒棒糖更新我注意到,与天然谷歌应用程序的状态栏的颜色改变以匹配您正在运行的应用程序的操作栏。我认为这是对Twitter的应用程序也让我猜它不完全是谷歌谁可以做到这一点。

In the new lollipop update I noticed that with the native Google apps the color of the status bar changes to match the action bar on the app you're running. I see it's on the Twitter app also so I'm guessing it's not exclusively Google who can do it.

有谁知道如何做到这一点,如果这是可能的吗?

Does anyone know how to do this if it is possible?

推荐答案

要更改状态栏的颜色使用的 setStatusBarColor(INT颜色)。 据javadoc的,我们还需要在窗口上设置一些标志。

To change status bar color use setStatusBarColor(int color). According the javadoc, we also need set some flags on the window.

的code工作片段:

Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(activity.getResources().getColor(R.color.example_color));

请记住 状态栏的颜色和操作栏的颜色应该是不同的:

Keep in mind according Material Design guidelines status bar color and action bar color should be different:

的动作条的应该使用小学500色 的状态条的应该使用小学700色 ActionBar should use primary 500 color StatusBar should use primary 700 color

看下面的截图:

 
精彩推荐
图片推荐