如何在菜单显示时拦截按键事件
我已经重写了 Activity 的 onKeyDown (int keyCode, KeyEvent event) 方法,以便记录用户按键操作。我进一步扩展了布局中使用的所有视图,并覆盖了 onKeyDown 方法。这样我就可以在我的大部分应用程序中记录硬键按下情况。仅当选项菜单或上下文菜单打开时,我无法拦截任何硬键按下以将其写入日志文件。有谁知道如何/是否可以做到这一点?是否可以将 OnKeyListener 或 OnKeyDownListener 附加到菜单?预先感谢您的帮助和努力!
I have already overriden the onKeyDown (int keyCode, KeyEvent event) method of my Activity in oder to log user key presses. I have further extended all Views I use in the layout and overriden the onKeyDown method there as well. That way I can log hardkey presses throughout most of my application. Only if an option menu or context menu is open, i cannot intercept any hard key presses to write them to the logfile. Does anybody know how/whether this can be done? Is it possible to attach an OnKeyListener or OnKeyDownListener to a menu?. Thanks in advance for your help and efforts!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不需要。您只需记录已选择特定菜单项的事实即可。
You don't need to. You can just log the fact that the particular menu item has been choosen.