if ((Build.VERSION.SDK_INT >= 28)) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
Field t= null;
try {
t = lp.getClass().getField("layoutInDisplayCutoutMode");
t.setInt(lp,1);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
getWindow().setAttributes(lp);
}
通过设置layoutparams 去掉头部黑边 强制顶部显示