简体   繁体   English

什么时候触摸AlertDialog外部的屏幕会取消AlertDialog?

[英]When does touching the screen outside an AlertDialog cancel the AlertDialog?

Suppose you have an AlertDialog with two buttons A and B. I have found that on some devices and some versions of android, if you touch any area of the screen around the dialog, the AlertDialog disappears. 假设您有一个带有两个按钮A和B的AlertDialog 。我发现在某些设备和某些版本的android上,如果您触摸对话框周围屏幕的任何区域,则AlertDialog消失。 On other devices you are forced to select either A or B, so there is no way I can allow the user to cancel the action without adding a third ('Cancel') option to the AlertDialog . 在其他设备上,您被迫选择A或B,因此,如果不向AlertDialog添加第三个(“取消”)选项,则不允许用户取消操作。 Is there any way to determine programmatically whether the third option is required? 是否可以通过编程方式确定是否需要第三种选择?

You can control it with dialog.setCanceledOnTouchOutside(true); 您可以使用dialog.setCanceledOnTouchOutside(true);来控制它dialog.setCanceledOnTouchOutside(true);

For more information : 欲获得更多信息 :

How to dismiss the dialog with click on outside of the dialog? 如何在对话框外部单击以关闭对话框?

Dialog dialog = new Dialog(context)
 dialog.setCanceledOnTouchOutside(true);

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

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