Android沉浸式状态栏,用的是开源库SystemBarTint。

demo下载地址:http://download.csdn.net/download/shenyuanqing/9226623

效果图:

依次(Android5.0及以上)->(Android4.4及以上)->(Android4.4以下)

Android沉浸式状态栏、导航栏_第1张图片Android沉浸式状态栏、导航栏_第2张图片

步骤:

1.添加类SystemBarTintManager到项目中

2.添加代码

        //Android4.4及以上版本才能设置此效果        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            //Android5.0版本            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS                        | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);                //设置状态栏颜色                getWindow().setStatusBarColor(getResources().getColor(R.color.green));                //设置导航栏颜色                getWindow().setNavigationBarColor(getResources().getColor(R.color.green));            }else {                //透明状态栏                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);                //透明导航栏                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);                //创建状态栏的管理实例                SystemBarTintManager tintManager = new SystemBarTintManager(this);                //激活状态栏设置                tintManager.setStatusBarTintEnabled(true);                //设置状态栏颜色                tintManager.setTintResource(R.color.green);                //激活导航栏设置                tintManager.setNavigationBarTintEnabled(true);                //设置导航栏颜色                tintManager.setNavigationBarTintResource(R.color.green);            }        }


3.XML最外层布局加下面属性,不然会有什么情况自己对比下就知道了

android:fitsSystemWindows="true"




更多相关文章

  1. RatingBar 显示正常版本----断点记录
  2. android 圆角按钮和按钮颜色
  3. android中实现带图片和checkbox的listview
  4. 边缘图片android布局属性详解
  5. Android提示版本更新的实现
  6. Android缩放图片Bitmap、Drawable
  7. Android ADT和SDK历史版本离线包下载地址
  8. Android获取设备型号和系统版本号、mac地址、IP、屏幕的分辨率
  9. android版本对应表

随机推荐

  1. 在android中使用SQLite数据库
  2. 远程调试android
  3. Android SeekBar样式修改实现签到效果
  4. android中获取context的多种方法的区别(th
  5. android开发系列之数据存储
  6. Android中在sdcard上创建文件夹,注意加权
  7. Android翻页效果原理实现之引入折线
  8. Android 获取imei号码,获取手机型号和系统
  9. Android 读取通信录号码
  10. Android输入框格式化Edittexthelp(有项目