在长时间运行的操作中,我显示了一个弹出对话框(从 ProgressDialog
创建以防止发生其他操作).
In a long-running operation, I'm showing a popup dialog (created from ProgressDialog
to prevent other operations from happening).
我已使用 setCancelable(false)
使其不可取消,因此我无法使用后退按钮将其关闭,但令人惊讶的是,搜索硬件按钮会关闭对话框!
I have made it non-cancellable with setCancelable(false)
, so I can't close it using the back button, but surprisingly, the Search hardware button dismisses the dialog!
更准确地说,显示了全局搜索应用程序,当我回到我的应用程序时,对话框已被关闭.
More exactly, the global search application is displayed, and when I come back to my app, the dialog has been dismissed.
知道如何防止对话框被关闭吗?
Any idea how to prevent the dialog from being dismissed?
这行得通(注意我把它放在对话框生成器上):
This works (notice I put it on the dialog builder):
.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
return true; // Pretend we processed it
}
return false; // Any other keys are still processed as normal
}
})
也许甚至可以抓住正负按钮按下,仅处理这些,对任何其他键返回 true.如果你能弄清楚那会很好奇......
Maybe it's even possible to grab the positive and negative button presses, and only handle these, return true for any other keys. Would be curious if you can figure that out...
PS:我在某处读到对话框中有更多漏洞",即您无需点击任何按钮即可摆脱它.这显然是一个.有人知道其他人吗?
PS: I read somewhere there are more "holes" in the dialog, i.e you can get rid of it without hitting any buttons on it. This was apparently one. Does anybody know of any others?
这篇关于当我单击搜索按钮时,防止 ProgressDialog 被关闭(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!