activity继承Cocos2dxActivity后无法监听安卓返回按键
2015-02-27 19:46
351 查看
前提:
原因:
Called when a key was pressed down and not handled by any of the views inside of the activity. So, for example, key presses while the cursor is inside a TextView will not trigger the event (unless it is a navigation to another
object) because TextView handles its own key presses.If the focused view didn't want this event, this method is called.
处理:
修改org.cocos2dx.lib.Cocos2dxGLSurfaceView
原:
参考:http://50vip.com/blog.php?i=390
public class TestActivity extends Cocos2dxActivity { @Override public boolean onKeyDown( int keyCode, KeyEvent event) {// 监听不到
原因:
Called when a key was pressed down and not handled by any of the views inside of the activity. So, for example, key presses while the cursor is inside a TextView will not trigger the event (unless it is a navigation to another
object) because TextView handles its own key presses.If the focused view didn't want this event, this method is called.
处理:
修改org.cocos2dx.lib.Cocos2dxGLSurfaceView
原:
@Override public boolean onKeyDown (final int pKeyCode, final KeyEvent pKeyEvent) { switch (pKeyCode) { case KeyEvent. KEYCODE_BACK: case KeyEvent. KEYCODE_MENU: this.queueEvent( new Runnable() { @Override public void run() { Cocos2dxGLSurfaceView.this. mCocos2dxRenderer.handleKeyDown(pKeyCode); } }); return true; default: return super.onKeyDown(pKeyCode, pKeyEvent); } }改:
@Override public boolean onKeyDown( final int pKeyCode, final KeyEvent pKeyEvent) { switch (pKeyCode) { case KeyEvent. KEYCODE_BACK: return false; case KeyEvent. KEYCODE_MENU: this.queueEvent( new Runnable() { @Override public void run() { Cocos2dxGLSurfaceView.this. mCocos2dxRenderer.handleKeyDown(pKeyCode); } }); return true; default: return super.onKeyDown(pKeyCode, pKeyEvent); } }经测试可正常监听返回按键
参考:http://50vip.com/blog.php?i=390
相关文章推荐
- 我在接入安卓SDK时,关于Activity继承Cocos2dxActivity onkeydown无法监测的问题
- TabActivity中监听按键响应(返回键)
- [转]TabActivity中监听按键响应(返回键)
- Activity监听返回按键
- 安卓奇葩问题之:返回按键监听,使Dialog不消失
- android 当Activity中弹出对话框时,无法监听返回键
- android 当Activity中弹出对话框时,无法监听返回键
- android 当Activity中弹出对话框时,无法监听返回键
- Unity3D与Android项目交互中无法监听back键返回的解决办法
- Unity3D与Android项目交互中无法监听back键返回的解决办法
- 笔记:安卓完全退出应用程序出现闪退、返回上一个activity的问题
- startActivityForResult ,无法接收到返回的resultCode的原因
- cocos2dx 安卓返回键的监听
- Activity中 左滑动返回监听
- ActivityGroup中监听返回按键
- 安卓点击返回按键退出应用程序
- 监听输入框返回按键
- 解决在使用tab时里面嵌套activity,不能正确监听返回键异常
- TabActivity中监听按键响应
- Android在输入法界面监听按键(以返回键为例)