所谓沉浸式状态栏确切的说就是设置状态栏颜色与整体布局一致。一般情况下,状态栏的底色都为黑色,而沉浸式状态栏则是把状态栏设置为透明或者半透明,然后设置状态栏色值。
因为沉浸式状态栏是在Android4.4的时候出现的,所以只有4.4及以后的版本才能使用,也就是API19以后版本可以使用。
1 SystemBarTint jar
2 SystemBarTint库
git地址:https://github.com/jgilfelt/SystemBarTint
3 着色开始
android:fitsSystemWindows="true"
在BaseActivity传入封装代码就可以简单实现着色了
private void stateColror(int color) {
if (android.os.Build.VERSION.SDK_INT > 18) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 创建状态栏的管理实例
SystemBarTintManager tintManager = new SystemBarTintManager(this);
// 激活状态栏设置
tintManager.setStatusBarTintEnabled(true);
// 激活导航栏设置
tintManager.setNavigationBarTintEnabled(true);
// 设置一个颜色给系统栏
tintManager.setTintColor(color);
}
}