/**
* 解决7.0沉浸式状态栏灰色
*/
protected void setSystem7Gray() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
Class decorViewClazz = Class.forName("com.android.internal.policy.DecorView");
Field field = decorViewClazz.getDeclaredField("mSemiTransparentStatusBarColor");
field.setAccessible(true);
field.setInt(getWindow().getDecorView(), Color.TRANSPARENT); //改为透明
} catch (Exception e) {
LogUtil.e("设置7.0沉浸式状态栏失败");
}
}
}
/**
* 设置透明导航栏
*/
protected void setTransNavigation() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//设置透明状态栏
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);//设置透明导航栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//注意要清除 FLAG_TRANSLUCENT_STATUS flag
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(getResources().getColor(android.R.color.transparent));
getWindow().getDecorView().setSystemUiVisibility(/*View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | */View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
【Android 7.0 沉浸式状态栏实现!! 】
最新推荐文章于 2022-01-17 15:19:24 发布