//沉浸式状态栏
//首先判断Api版本号是否大于19也就是Android4.4
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
//判断Api版本号是否大于21也就是Android6.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//获取窗体
Window window = getWindow();
//获取窗体的参数
WindowManager.LayoutParams attributes = window.getAttributes();
//设置一个值
attributes.flags |= flagTranslucentNavigation;
//再将它赋给attributes
window.setAttributes(attributes);
//设置状态栏为透明
getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
Window window = getWindow();
WindowManager.LayoutParams attributes = window.getAttributes();
attributes.flags |= flagTranslucentStatus | flagTranslucentNavigation;
window.setAttributes(attributes);
}
}