修改系统状态栏颜色

来源:互联网 发布:软件开发毕业设计题目 编辑:程序博客网 时间:2024/05/20 23:02

SystemBarTintManager

修改需要三步操作:

1、在activity的xml文件的根控件添加个属性:

android:clipToPadding="true"

android:fitsSystemWindows="true"


2、在oncreate方法中添加如下代码

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {     setTranslucentStatus(this, true);   }   // 创建状态栏的管理实例   SystemBarTintManager tintManager = new SystemBarTintManager(this);   // 激活状态栏设置   tintManager.setStatusBarTintEnabled(true);   // 激活导航栏设置   tintManager.setNavigationBarTintEnabled(true);   // 设置一个颜色给系统栏   tintManager.setTintColor(ContextCompat.getColor(this,R.color.sysbarcolor));
setTranslucentStatus
方法如下:
@TargetApi(Build.VERSION_CODES.KITKAT)private static void setTranslucentStatus(Activity activity, boolean on) {    Window win = activity.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);}
SystemBarTintManager 的链接


0 0
原创粉丝点击