基于SystemBarTint实现

第一步

首先将SystemBarTintManager类放入项目。

下载链接:http://download.csdn.net/detail/u013193363/9339781

第二步

在activity对应的布局文件中加入两行代码

android:fitsSystemWindows=”true”
android:clipToPadding=”true”

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="true"    android:clipToPadding="true"    >

第三步

onCreat()方法中调用initSystemBar()方法

    private void initSystemBar() {          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {              setTranslucentStatus(true);          }          SystemBarTintManager tintManager = new SystemBarTintManager(this);          tintManager.setStatusBarTintEnabled(true);          //使用颜色资源          //tintManager.setStatusBarTintResource(R.color.systemBar_color);          //使用图片资源                                                                 tintManager.setStatusBarTintDrawable(getResources().getDrawable(R.drawable.ic_top_title_background));      }      @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);        }    

颜色资源文件

在res->values 新建color.xml

<?xml version="1.0" encoding="utf-8"?>  <resources xmlns:android="http://schemas.android.com/apk/res/android">      <color name="systemBar_color">#2aa45acolor>  resources>

此上转载于:http://blog.csdn.net/s1e1s/article/details/46558681

**至此,就可以实现,沉浸式状态栏了。

在做项目过程中,发现除了沉浸状态栏,还可以透明虚拟键,也就是页面布局会在虚拟键之下**

又看到了这个关于沉浸式的介绍也不错,可以参考看看。
http://www.jianshu.com/p/f8374d6267ef

在 KITKAT 之后,Android Window支持了一些新的属性,其中有两个是这样的 .

WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS //状态栏
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION //导航栏

正如它们的变量名的意思,使用这两个属性,可以使得状态栏和导航栏变为透明,
导航栏指的就是Android下方的三大按键,当然只使用第一个属性也可以达到今天所要完成的效果。

更多相关文章

  1. Android10共享文件总是读取不到文件,文件资源不存在!
  2. android EditText 属性
  3. android 属性android:visibility
  4. [转]android颜色对应的xml配置值
  5. Activity 全透明属性
  6. Android 字体颜色渐变效果 Span实现

随机推荐

  1. 2022讲师招募、课程合作计划(php中文网)
  2. 新手小白sai如何画线稿?初学者绘制线稿步
  3. 【北亚数据恢复】oracle数据库执行trunca
  4. 实践:Linux下安装mysql8.0
  5. 淘宝 NPM 镜像站切换新域名啦
  6. ModStartCMS 模块化建站系统 Laravel 9.0
  7. 学习java的十大理由
  8. ModStartCMS模块化建站系统 v3.3.0 组件
  9. PyCharm的基本设置【图文详细讲解】
  10. php数据流中第K大元素的计算方法及代码分