1.对于4.4版本以上的安卓App想要实现沉浸式状态栏应该在Activity布局中中加上一行代码
getWindow().addFlags(WindowManager. LayoutParams.FlAG_TRANSLUCENT_ STATUS);
2.由于加入透明状态栏后,会使页面整个布局往上移动,要想使页面位置不变,就需要在整个页面布局之上中加入
fitsSystemWindows:true
clipToPadding:true
该代码用于设置padding,使页面不会上移。
如果要想设置状态栏的颜色,应该使用一个开源库SystemBarTint
private void initSystemBar() {
if (Build.VERSION.SDK_INT >=
Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
SystemBarTintManagertintManager =
new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
//设置颜色
//tintManager.setTintColor();
tintManager.setStatusBarTintResource(
R.color.actionbar_bg);
SystemBarConfigconfig =
tintManager.getConfig();
//设置Padding
listViewDrawer.setPadding(0,
config.getPixelInsetTop(true),0,
config.getPixelInsetBottom());
}
}