private static IToast newToast(ToastUtils toastUtils) {
if (!toastUtils.isNotUseSystemToast) {
if (NotificationManagerCompat.from(Utils.getApp()).areNotificationsEnabled()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return new SystemToast(toastUtils);
}
if (!UtilsBridge.isGrantedDrawOverlays()) {
return new SystemToast(toastUtils);
}
}
}
// not use system or notification disable
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_TOAST);
} else if (UtilsBridge.isGrantedDrawOverlays()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_PHONE);
}
}
return new ActivityToast(toastUtils);
}
@Blankj Blankj大神,android 9机器上我遇到悬浮窗遮挡toast的情况, A悬浮窗设置的type=TYPE_APPLICATION_OVERLAY。按我对书本层级这段理解,只有欲显示的B窗口type >= TYPE_APPLICATION_OVERLAY时,才有可能显示在A窗口上面。
所以使用ActivityToast怎么做都只能显示在A悬浮窗下面, 不知理解这否正确?
那边你的代码
else if (UtilsBridge.isGrantedDrawOverlays()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_PHONE);
}
}
return new ActivityToast(toastUtils);
是不是写错了,应该改成:
else if (UtilsBridge.isGrantedDrawOverlays()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_PHONE);
}
}
return new ActivityToast(toastUtils);