如何检测,当用户presses"菜单"他们的Andr​​oid设备上的关键? [英] How to detect when user presses "menu" key on their Android device?

查看:85
本文介绍了如何检测,当用户presses"菜单"他们的Andr​​oid设备上的关键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以重写 onBack pressed()较高的API级别,以检测返回键是pressed。有没有一种类似的方式来做到这一点的菜单按钮?我不在的KeyEvents检查重点code的忠实粉丝。谢谢!

I know I can override onBackPressed() on higher API levels to detect if the back key is pressed. Is there a similar way to do it for the menu button? I'm not a big fan of checking keycode in KeyEvents. Thanks!

推荐答案

如果你只是希望创建一个按键侦听器的菜单按钮,你应该重写<一href="http://developer.android.com/reference/android/app/Activity.html#onKeyDown%28int,%20android.view.KeyEvent%29">onKeyDown并检查关键code。现在,既然你指出,你不是说你也可以重写<一个大风扇href="http://developer.android.com/reference/android/app/Activity.html#on$p$ppareOptionsMenu%28android.view.Menu%29">on$p$ppareOptionsMenu这被称为每次菜单按钮被点击和一个菜单显示给用户。我不知道大家有没有提供内部的<一个菜单这就是所谓的href="http://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu%28android.view.Menu%29">onCreateOptionsMenu方法。

If you are just looking to create a key listener for the menu button you should be overriding onKeyDown and checking the keycode. Now since you pointed out that you are not a big fan of that you could also override onPrepareOptionsMenu which is called everytime the menu button is clicked and a menu is shown to the user. I am not sure if this is called if you have not supplied a menu inside the onCreateOptionsMenu method.

这篇关于如何检测,当用户presses&QUOT;菜单&QUOT;他们的Andr​​oid设备上的关键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆