美文网首页
设置系统状态栏颜色

设置系统状态栏颜色

作者: Jarhot | 来源:发表于2017-06-23 11:00 被阅读0次
 /**
     * 设置系统状态栏颜色
     */
    private void setTintColor() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            // enable status bar tint
            tintManager.setStatusBarTintEnabled(true);
            // enable navigation bar tint
            tintManager.setNavigationBarTintEnabled(true);
            tintManager.setTintColor(Color.BLACK);
        }
    }

    @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);
    }

dependencies {
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
}

github传送门

相关文章

网友评论

      本文标题:设置系统状态栏颜色

      本文链接:https://www.haomeiwen.com/subject/plxccxtx.html