天天看点

借助SystemBarTint实现透明标题栏(沉浸式)

  • 首先添加依赖.
    compile ‘com.readystatesoftware.systembartint:systembartint:1.0.3’
  • 将状态栏设置为透明.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏                 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
           
  • 设置状态栏颜色.
// 创建状态栏的管理实例
SystemBarTintManager tintManager = new SystemBarTintManager(this);
// 激活状态栏设置
tintManager.setStatusBarTintEnabled(true);
// 激活导航栏设置
tintManager.setNavigationBarTintEnabled(true);
// 设置一个颜色给系统栏
tintManager.setTintColor(Color.parseColor("#40C4FF"));
           

在颜色设置里通过R.color.item好像不可以,该方法需要传入一个string类型的颜色描述,R.xxx传递的是int的资源参数.

这样的设置下,Activity回合标题栏重叠,还需要在布局文件里加上

android:fitsSystemWindows=”true”

android:clipToPadding=”true”

才可以正常的显示.

然后..就没有鸟.