SystemBarTint的使用

来源:互联网 发布:简单网络机房图片 编辑:程序博客网 时间:2024/06/09 19:26

SystemBarTint的使用

1、导入.jar包
compile ‘com.readystatesoftware.systembartint:systembartint:1.0.3’

2、xml布局文件修改
在Activity的布局文件里的顶层布局加代码,如下:
android:fitsSystemWindows=”true”
作用是让view可以根据系统窗口(如status bar)来调整自己的布局,如果值为true,就会调整view的paingding属性来给system windows留出空间。

3、Activity代码
private void setTranslucentSystemBar() {
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintColor(R.color.title_bar_bg);
// 4.4及以上版本开启
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
//透明状态栏
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}

1 0
原创粉丝点击