设置android状态栏颜色和toolbar颜色一致

1、导入jar包,我用的是systembartint-1.0.4.jar–>add as library
2、在主题文件style标签内加入属性:

<item name="android:windowTranslucentStatus">true</item>

3、在要设置沉浸模式的activity的布局文件中加入属性:

android:fitsSystemWindows="true"

4、在要设置沉浸模式的activity的onCreate()方法中加入代码:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            Window win = getWindow();            WindowManager.LayoutParams winParams = win.getAttributes();            final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;            winParams.flags |= bits;            win.setAttributes(winParams);            SystemBarTintManager tintManager = new SystemBarTintManager(this);            tintManager.setStatusBarTintEnabled(true);            tintManager.setStatusBarTintResource(R.color.colorPrimary);        }

检测当android版本在4.4以上就启用透明状态栏,设置与Toolbar一致的颜色。
效果图如下:

更多相关文章

  1. Android(安卓)界面的基本属性
  2. 有关布局问题:TextView、EditText……(二)
  3. Android(安卓)OpenGL 开发
  4. 设置activity为Dialog类型的设置
  5. Android(安卓)ImageView图片显示点击背景切换
  6. 【Android开发基础】应用界面主题Theme使用方法
  7. android 简单快速 倒计时动画
  8. android中TextView图文混排
  9. 布局与控件(三)-TextView那些事儿

随机推荐

  1. 2021.1.28
  2. js002-getElementsByName,getElementById
  3. 分支语句
  4. 字节尿性,康托展开求第K个排列!
  5. 又一个同学被快手挂掉了
  6. 如果宁静是Oracle,那万茜,张雨绮,黄圣依 是
  7. 万字长文!二叉树入门和刷题看这篇就够了!
  8. 蚂蚁上市朋友圈都有些什么神仙声音?
  9. 小姐姐提灯给你讲讲动态规划(万字长文)
  10. Spring Boot 解决跨域问题的 3 种方案!