Android P上判断是否刘海屏的方法

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    WindowInsets windowInsets = decorView.getRootWindowInsets();    
    if (windowInsets != null) {
        DisplayCutout displayCutout = windowInsets.getDisplayCutout();        
        if (displayCutout != null) {            
            List rects = displayCutout.getBoundingRects();            
            //通过判断是否存在rects来确定是否刘海屏手机
            if (rects != null && rects.size() > 0) {
                isNotchScreen = true;
            }
        }
    }
}

你可能感兴趣的:(Android P上判断是否刘海屏的方法)