我显示一个对话框,其中包含一个关闭按钮和一个用于打开新对话框的按钮。除非我在当前对话框之上打开第二个对话框,否则关闭按钮工作正常。我认为我的对话框失去了焦点并且无法关闭。
public void anotherOne(View v){
openDialog2(); //This opens another dialog on top of the current one
}
public void closeDialog(View v){
dialog.cancel(); //This works fine unless anotherOne() has been called and closed
}
即使在打开和关闭当前对话框之上的另一个对话框后,如何将焦点重新附加到当前对话框?
最佳答案
你应该在第二个对话的onClick方法中取消第二个对话后取消第一个对话
对该链接收费stack question
编辑:
尝试以编程方式设置可取消属性
dialog.setCancelable(true);//will cancel dialog onBackPressed() and when negative button clicked
dialog.setCanceledOnTouchOutside(true); // will cancel when user touches screen outside the dialog's box
关于java - 失去焦点后无法取消对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47949751/