fix(target O): floating window cannot be shown

This commit is contained in:
hyb1996
2018-10-06 11:16:27 +08:00
parent 0ff7b1c208
commit 54cbb78d8e
6 changed files with 37 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;
@@ -15,10 +16,17 @@ public class DialogUtils {
public static <T extends Dialog> T showDialog(T dialog) {
Context context = dialog.getContext();
if (!isActivityContext(context)) {
Window window = dialog.getWindow();
int type;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
type = WindowManager.LayoutParams.TYPE_PHONE;
}
if (window != null)
window.setType(WindowManager.LayoutParams.TYPE_PHONE);
window.setType(type);
}
dialog.show();
return dialog;