/**
* 判断当前是否是刘海屏,目前只是针对于Android P有效,其他的默认都是非刘海屏
* @return
*/
public static boolean isNotchScreen(Activity activity)
{
boolean isNotchScreen = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowInsets windowInsets = activity.getWindow().getDecorView().getRootWindowInsets();
if (windowInsets != null) {
DisplayCutout displayCutout = windowInsets.getDisplayCutout();
if (displayCutout != null) {
List<Rect> rects = displayCutout.getBoundingRects();
//通过判断是否存在rects来确定是否刘海屏手机
if (rects != null && rects.size() > 0) {
isNotchScreen = true;
}
}
}
}
return isNotchScreen;
}
if ((Build.VERSION.SDK_INT >= 28) && Utils.isNotchScreen(this))
{
//设置页面全屏显示
//设置页面延伸到刘海区显示
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//允许全屏app使用刘海屏
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(lp);
}
else
{
// 全屏展示
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}