android如何更改状态栏颜色

来源:互联网 发布:java后端需要学什么 编辑:程序博客网 时间:2024/04/28 17:04

github上有一个改变状态栏颜色的项目,点我

然后使用方法如下,点我

注意,这里只能在android4.4版本以上更改状态栏颜色,亲测4.4以下版本,如4.1不可以

如果不看上面的使用方法的帖子,下面将使用方法摘出来,在activity中加入如下代码

public void changeSystemBarColor(){        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            setTranslucentStatus(true);            SystemBarTintManager tintManager = new SystemBarTintManager(this);            tintManager.setStatusBarTintEnabled(true);            tintManager.setStatusBarTintResource(R.color.colorAccent);//通知栏所需颜色        }    }    @TargetApi(19)    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);    }

然后再在increase方法中调用changeSystemBarColor即可,其中R.color.colorAccent中的color颜色要在color.xml中进行设置

大功告成!

1 0
原创粉丝点击