设置android状态栏颜色和toolbar颜色一致
1、导入jar包,我用的是systembartint-1.0.4.jar–>add as library
2、在主题文件style标签内加入属性:
<item name="android:windowTranslucentStatus">true</item>
3、在要设置沉浸模式的activity的布局文件中加入属性:
android:fitsSystemWindows="true"
4、在要设置沉浸模式的activity的onCreate()方法中加入代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
winParams.flags |= bits;
win.setAttributes(winParams);
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.colorPrimary);
}
检测当android版本在4.4以上就启用透明状态栏,设置与Toolbar一致的颜色。
效果图如下: