Android状态栏沉浸的实现

最近安卓的沉浸栏十分受欢迎。
用到了开源的库。Android System Bar Tint 地址:https://github.com/jgilfelt/SystemBarTint
如果不自己自定义的话,只能用于Android 4.4以上的系统。
目前我写的这个也只能用于Android4.4以上的,并且可以兼容ActionBar

步骤:1.设置状态栏透明,然后设置状态栏沉浸的颜色
@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);
}

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

步骤2:设置适应windows,在布局文件设置
android:fitsSystemWindows=”true”

这样就可以实现了。

你可能感兴趣的:(Android状态栏沉浸的实现)