Android 后退按钮覆盖帮助
我正在制作一个应用程序,一个游戏,我希望玩家能够使用后退按钮进行跳跃(对于单点触摸设备)。我的目标平台是2.1(API级别7)。
我已经尝试过 onKeyDown() 和 onBackPressed(),但它们仅在释放后退按钮时调用,而不是在按下后退按钮时调用。
1)这正常吗?
2)如何才能在按下按钮时记录按下情况?
编辑: 我还想补充一点,它使用键盘可以正常工作(按下键时会调用 onKeyDown)。
I am making an app, a game, and I want the player to be able to use the back button for jumping(for single-touch devices). My target platform is 2.1(API level 7).
I've tried both onKeyDown() and onBackPressed(), but they are only called when the back button is RELEASED, not when it is pressed down.
1) Is this normal?
2) How can I make it so it registers the press when the button is pressed?
EDIT:
I'd also like to add that it works correctly using a keyboard(onKeyDown is called when a key is pressed down).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:我对此很好奇。看一下 android.view.View 源代码: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/view/View.java
代码:
使用dispatchKeyEvent:
独立记录两个事件即使是后退键。由于某种原因,唯一未记录的密钥是
KEYCODE_HOME
。事实上,如果您保持按下后退按钮,您将连续看到多个ACTION_DOWN
(0) 事件(如果您return false;
则会看到更多事件)。在 Eclair 模拟器和 Samsung Captivate(定制 Froyo ROM)中进行了测试。Update: I got curious about this. Take a look at the android.view.View source code: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/view/View.java
code:
Using dispatchKeyEvent:
Logs the two events independently even for the back key. The only key that did not log was
KEYCODE_HOME
, for some reason. In fact, if you maintain the back button pressed, you will see severalACTION_DOWN
(0) events in a row (and much more if youreturn false;
instead). Tested in an Eclair emulator and a Samsung Captivate (custom Froyo ROM).