简体   繁体   English

Android:如何在 PIP 模式下显示 AlertDialog?

[英]Android: How to show AlertDialog in PIP mode?

Whenever there is an error we are showing AlertDialog to inform user.每当出现错误时,我们都会显示 AlertDialog 以通知用户。 But when in PIP mode this dialog is rendered inside PIP window as it can be seen in attached screenshots.但是在 PIP 模式下,此对话框会在 PIP window 中呈现,如随附的屏幕截图所示。 Is there any way to show proper alert AlertDialog out side PIP window?有什么方法可以在 PIP window 之外显示正确的警报 AlertDialog 吗?

在此处输入图像描述

I had a similar problem while exiting pip and entering back to the main activity while a dialog was showing.我在退出 pip 并在显示对话框时返回主活动时遇到了类似的问题。 When the user came back to the application the dialog was enlarged and the user was not able to close the dialog (he needed to go back and forth just to close it).当用户回到应用程序时,对话框被放大并且用户无法关闭对话框(他需要来回 go 才能关闭它)。 I found a simple fix to my problem (hopefully it will help in your case as well) What you need to do is to adjust the bounderies of the dialog.我找到了一个简单的解决我的问题的方法(希望它对你的情况也有帮助)你需要做的是调整对话框的边界。

When you create AlertDialog or DialogFragment override the onShow() function当您创建 AlertDialog 或 DialogFragment 覆盖 onShow() function

@Override
public AlertDialog show() {
   AlertDialog dialog =  super.show();

   int width =  WindowManager.LayoutParams.WRAP_CONTENT;
   int height =  WindowManager.LayoutParams.WRAP_CONTENT;

   dialog.getWindow().setLayout(width, height);

   return dialog;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM