美文网首页
沉浸式状态栏的实现

沉浸式状态栏的实现

作者: HelloFeiGe | 来源:发表于2017-03-22 10:42 被阅读0次

    1: 添加依赖

    //沉浸式状态栏

    compile'com.readystatesoftware.systembartint:systembartint:1.0.3'

    2: 在根布局添加属性

    android:fitsSystemWindows="true"

    android:clipToPadding="false"

    android:fitsSystemWindows="true"   这个属性的作用就是你的contentview是否忽略actionbar,title,屏幕的底部虚拟按键,将整个屏幕当作可用的空间。

    正常情况,contentview可用的空间是去除了actionbar,title,底部按键的空间后剩余的可用区域;这个属性设置为true,则忽略,false则不忽略

    android:clipToPadding="false"  这个属性是:控件的绘制区域是否在padding里面, 值为true时padding那么绘制的区域就不包括padding区域;

    3:调用着色代码

    private voidinitSystemBar() {

    if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.KITKAT) {

    Window win = getWindow();

    WindowManager.LayoutParams winParams = win.getAttributes();

    //修改window的综合属性flags//WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS含义为状态栏透明winParams.flags|= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;

    win.setAttributes(winParams);

    }

    //调用开源库SystemBarTintManager进行状态栏着色 产生沉浸式效果SystemBarTintManager tintManager =newSystemBarTintManager(this);

    tintManager.setStatusBarTintEnabled(true);//使用状态栏着色可用tintManager.setStatusBarTintColor(Color.GREEN);//指定颜色进行着色}

    相关文章

      网友评论

          本文标题:沉浸式状态栏的实现

          本文链接:https://www.haomeiwen.com/subject/yotonttx.html