Android 改变状态栏颜色

来源:互联网 发布:综漫之知世 编辑:程序博客网 时间:2024/05/06 05:06
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){setTranslucentStatus(true);}SystemBarTintManager tintManager = new SystemBarTintManager(this);tintManager.setStatusBarTintEnabled(true);tintManager.setStatusBarTintResource(R.color.statusbar_bg);

R.color.statusbar_bg   项目主题色

private void setTranslucentStatus(boolean on){Window win = getWindow();WindowManager.LayoutParams winParams = win.getAttributes();final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;if (on){winParams.flags |= bits;}else{winParams.flags &= ~bits;}win.setAttributes(winParams);}
android:fitsSystemWindows="true"  // 需要沉浸式布局的xml加在最外面的布局属性内


https://github.com/jgilfelt/SystemBarTint   需要jar包

0 0