fix(target O): floating window cannot be shown
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user