android - 什么时候触摸 AlertDialog 之外的屏幕会取消 AlertDialog?

标签 android android-alertdialog

假设您有一个带有两个按钮 A 和 B 的 AlertDialog。我发现在某些设备和某些 Android 版本上,如果您触摸对话框周围屏幕的任何区域,AlertDialog 消失。在其他设备上,您必须选择 A 或 B,因此如果不向 AlertDialog 添加第三个(“取消”)选项,我就无法允许用户取消操作。有没有办法以编程方式确定是否需要第三个选项?

最佳答案

您可以通过 dialog.setCanceledOnTouchOutside(true); 来控制它

了解更多信息:

How to dismiss the dialog with click on outside of the dialog?

关于android - 什么时候触摸 AlertDialog 之外的屏幕会取消 AlertDialog?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26993860/

相关文章:

android - 检查 gradle 测试是否通过 shell 脚本

javascript - Android - 在外部网页上加载并执行javascript

android - 如何防止屏幕方向改变从相机 Intent 返回(SGS3)

android - Spinner 项目的自定义布局

java - 试图调用本地数据库变量并且应用程序停止工作

android - 如何为 alertDialog 创建自己的主题?

java - 以明文形式查看 UDP 消息时出现问题

android - 导航栏下方全屏视频

android - 如何像启动画面一样只运行一次 Activity

android - 如何在单击时禁用其他复选框(AlertBuilder)