android设置状态栏颜色
我们先来看看官方文档
setStatusBarColor
added in API level 21
public abstract void setStatusBarColor (int color)
Sets the color of the status bar to color. For this to take effect, the window must be drawing the system bar backgrounds with WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS and WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS must not be set. If color is not opaque, consider setting View.SYSTEM_UI_FLAG_LAYOUT_STABLE and View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN.
The transitionName for the view background will be "android:status:background".
我们来翻译一下
方法名:
setStatusBarColor
设置状态栏颜色
在API21加入
给状态栏设置颜色
为了产生效果,window对象必须设置
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
以及不能设置
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
如果颜色是透明的,那么要设置
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
好了,看完文档
我们来试一试
在activity里面设置一下
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ColorUtil.getColor(R.color.color_theme_blue));
OK
搞定