nickalc / StatusBarColor

设置大于兼容4.4版本的状态栏渐变色

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StatusBarColor

##设置大于4.4兼容版本的状态栏渐变色,让你的toolbar的状态栏在4.4以上版本实现5.0的Material Design效果

代码中的SystemBarTintManager文件引用了 SystemBarTint的开源类库,感谢作者的开源精神.

步骤

1.首先在res资源文件目录下建立values-19目录,只要系统版本大于kitkat系统会自己读取该目录下的style文件,将默认的values下的style中的主题样式拷贝到values-19目录下的style文件中,需要添加两个设置如下

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

2.在mainactivity的布局中的根标签下面设置如下参数


android:fitsSystemWindows="true"

3.然后代码中添加:


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.colorPrimaryDark);
        }

#####红米note4.4.4截图如下:

Alt text

Alt text

Alt text

#####解决之前样式问题导致nexus原生虚拟键栏bug问题,添加了虚拟键颜色样式 Alt text

About

设置大于兼容4.4版本的状态栏渐变色


Languages

Language:Java 100.0%