如何在 Android 中显示警报时检测搜索按钮
大家好,stackoverflow 的朋友们,
我最近遇到了一个问题,当屏幕上显示警报时,如何禁用 Android 中的全局搜索按钮。我不想通过使用搜索按钮来消失警报框。我需要用户必须单击警报框按钮并以这种方式消失。所以我想在显示警报框时禁用搜索按钮。但我可以使用 setCancable(false) 禁用后退按钮。我该如何解决这个问题?
提前致谢。
Hi stackoverflow friends
I recently faced an issue that how can i disable global search button in android while an alert is shown in the screen.I don't want to disappear the alert box by using search button. I need to user must click the alertbox button and disappears in that way.So I want to disable the search button while alert box is shown. But I can disable the back button using setCancable(false).How can I solve this ?
THanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,您的意图是提供不可取消的警报。
建议设置
OnDismissListener
并再次显示警报。从视觉角度来看这不是很好(警报关闭然后再次打开)。下面是一些如何实现此类不可取消警报的明显示例(代码位于 Acctivity 类内):
但是,我认为这不是为用户留下此类警报的正确方法,有时在评估限制等情况下可能需要它ETC。
So, Your intention is to provide non-cancelable alert.
Suggesting to set
OnDismissListener
and just show alert again. It's not very good from visual perspective (alert get closed and opened again).Below is some obvious example how to achieve such non-cancelable alert (code is inside Acctivity class):
However, I don't think it's the right way to left such alert for the user, sometimes it might be needed for cases like evaluation restriction etc.
覆盖 Activity 中的
onSearchRequested
并使其在显示对话框时返回false
。这应该会阻止请求,根据 docs:Override
onSearchRequested
in your Activity and have it returnfalse
while the dialog is being shown. This should block the request, as per the docs:只需将上面的代码添加到警报对话框生成器即可。希望这个片段会有所帮助。祝你好运。
Just add the code above to alert dialog builder. Hope this snippet would help. Good luck.