方法1:在页面跳转到非全屏显示的时候加上
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
使得其为非全屏提前变为非全屏显示
方法2:在非全屏显示的Activity中处理,在setContentView之前add一个和状态等高的View
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
ViewGroup rootView = ((ViewGroup) this.findViewById(android.R.id.content));
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
//状态栏的高度
int statusBarHeight = getResources().getDimensionPixelSize(resourceId); rootView.setPadding(0, statusBarHeight, 0, 0);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
ViewGroup decorViewGroup = (ViewGroup) getWindow().getDecorView(); View statusBarView = new View(getWindow().getContext()); FrameLayout.LayoutParams params = new
//设置状态栏的相关参数
FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, statusBarHeight);
params.gravity = Gravity.TOP;
statusBarView.setLayoutParams(params); statusBarView.setBackgroundColor(ContextCompat.getColor(context,R.color.text_666666));
//添加到DecorView中
decorViewGroup.addView(statusBarView); }