diff --git a/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIStatusBarHelper.java b/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIStatusBarHelper.java index 26495b81c..7677b383a 100644 --- a/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIStatusBarHelper.java +++ b/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIStatusBarHelper.java @@ -35,13 +35,11 @@ public class QMUIStatusBarHelper { private static Integer sTransparentValue; public static void translucent(Activity activity) { - translucent(activity, 0x40000000); + translucent(activity.getWindow()); } - private static boolean supportTranslucent() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT - // Essential Phone 在 Android 8 之前沉浸式做得不全,系统不从状态栏顶部开始布局却会下发 WindowInsets - && !(QMUIDeviceHelper.isEssentialPhone() && Build.VERSION.SDK_INT < Build.VERSION_CODES.O); + public static void translucent(Window window) { + translucent(window, 0x40000000); } /** @@ -50,13 +48,16 @@ private static boolean supportTranslucent() { * * @param activity 需要被设置沉浸式状态栏的 Activity。 */ - @TargetApi(19) public static void translucent(Activity activity, @ColorInt int colorOn5x) { + translucent(activity.getWindow(), colorOn5x); + } + + @TargetApi(19) + public static void translucent(Window window, @ColorInt int colorOn5x) { if (!supportTranslucent()) { // 版本小于4.4,绝对不考虑沉浸式 return; } - Window window = activity.getWindow(); // 小米和魅族4.4 以上版本支持沉浸式 if (QMUIDeviceHelper.isMeizu() || QMUIDeviceHelper.isMIUI()) { window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, @@ -64,11 +65,8 @@ public static void translucent(Activity activity, @ColorInt int colorOn5x) { return; } - if(QMUINotchHelper.isNotchOfficialSupport()){ - WindowManager.LayoutParams params = window.getAttributes(); - params.layoutInDisplayCutoutMode = WindowManager.LayoutParams - .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; - window.setAttributes(params); + if (QMUINotchHelper.isNotchOfficialSupport()) { + handleDisplayCutoutMode(window); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -103,6 +101,20 @@ public static void translucent(Activity activity, @ColorInt int colorOn5x) { } } + @TargetApi(28) + private static void handleDisplayCutoutMode(Window window) { + WindowManager.LayoutParams params = window.getAttributes(); + params.layoutInDisplayCutoutMode = WindowManager.LayoutParams + .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; + window.setAttributes(params); + } + + private static boolean supportTranslucent() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT + // Essential Phone 在 Android 8 之前沉浸式做得不全,系统不从状态栏顶部开始布局却会下发 WindowInsets + && !(QMUIDeviceHelper.isEssentialPhone() && Build.VERSION.SDK_INT < Build.VERSION_CODES.O); + } + /** * 设置状态栏黑色字体图标, * 支持 4.4 以上版本 MIUI 和 Flyme,以及 6.0 以上版本的其他 Android @@ -252,7 +264,7 @@ public static boolean MIUISetStatusBarLightMode(Window window, boolean light) { * 见小米开发文档说明:https://dev.mi.com/console/doc/detail?pId=1159 */ private static boolean isMIUICustomStatusBarLightModeImpl() { - if (QMUIDeviceHelper.isMIUIV9() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M){ + if (QMUIDeviceHelper.isMIUIV9() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } return QMUIDeviceHelper.isMIUIV5() || QMUIDeviceHelper.isMIUIV6() || diff --git a/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/util/QDNotchHelperFragment.java b/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/util/QDNotchHelperFragment.java index dd9e816c5..69da732ad 100644 --- a/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/util/QDNotchHelperFragment.java +++ b/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/util/QDNotchHelperFragment.java @@ -116,7 +116,7 @@ private void initTabs() { @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); -// changeToFullScreen(); + changeToFullScreen(); } private void changeToFullScreen() { diff --git a/qmuidemo/src/main/res/layout/fragment_notch.xml b/qmuidemo/src/main/res/layout/fragment_notch.xml index 0ae28d52f..c4d14468c 100644 --- a/qmuidemo/src/main/res/layout/fragment_notch.xml +++ b/qmuidemo/src/main/res/layout/fragment_notch.xml @@ -20,13 +20,6 @@ android:text="安全区域\nTODO vivo 显示与亮度-第三方应用显示比例\nTODO OPPO 设置-显示-应用全屏显示-凹形区域显示控制" android:textColor="@color/qmui_config_color_white" android:textSize="16sp"/> - -