//解决办法
Window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
附上沉浸代码片段
public class Utils { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); //取消状态栏透明 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 window.setStatusBarColor(statusColor); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); //让view不根据系统窗口来调整自己的布局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } } }
本文来自博客园,作者:世界如此简单,转载请注明原文链接:https://www.cnblogs.com/Gxiaoxi/p/14277128.html