Android 在菜单可见时处理按键事件
这是我的问题。
我覆盖了我的应用程序的音量减小键,以在长时间按下该键时执行某些特定任务,它正常工作。我可以为此拦截按键按下和按键按下事件。
关键侦听器事件是在特定的自定义组件中编写的,而不是在使用该组件的活动中编写的。
当我在按下音量减小键的同时按下菜单按钮,并且在显示菜单时松开菜单按钮时,会出现问题,我无法拦截其按键事件。
您能解释一下其背后的原因是什么吗?而这个问题能不能解决呢?
谢谢。
Here is my problem.
I override volume down key for my application to do some specific task while it's pressed for a long time, it works fine normally. I can intercept key down and key up events for that.
The key listener events are written in particular custom component and not in activity where this component is used.
Problem arises when I press menu button while I have pressed the volume down key, and when I release it while menu is shown, I can not intercept its key up event.
Can you explain what is the reason behind it? And if this problem can be solved or not?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单击菜单时,您的窗口焦点会发生变化。焦点转到菜单视图。因此 onKeyDown() 不起作用,因为如果屏幕焦点位于顶部的视图或活动上,onKeyDown 就会起作用。
使用下面的代码来了解屏幕的焦点
When Menu is clicked your window focus change. Focus come to Menu view. Because of this onKeyDown() does not work because onKeyDown wil work if the focus of the screen will be on the view or activity which is on top.
Use the following code to know focus of the screen