第一种方式:
直接修改Cocos2dxGLSurfaceVIEw类中的onKeyDown方法,修改如下:
<span >@OverrIDe public boolean onKeyDown(final int pKeyCode,final KeyEvent pKeyEvent) { switch (pKeyCode) { case KeyEvent.KEYCODE_BACK: Log.d("","KEYCODE_BACK+++++++++++++++++"); new AlertDialog.Builder(Spartacus.getActivity()) .setTitle(R.string.exit_tip) .setMessage(R.string.exit_message) .setNegativebutton(R.string.exit_cancel,new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog,int which) { } }) .setPositivebutton(R.string.exit_confirm,new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int whichbutton) { //finish(); System.exit(0); } }).show(); return true; 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); } }</span>
第二种方式:
1)、先修改修改Cocos2dxGLSurfaceVIEw类中的onKeyDown方法,修改如下:
@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); } }
2)、在继承自Cocos2dxActivity类的,我们自己的activity类中覆盖父类的onKeyDown方法:
@OverrIDe public boolean onKeyDown(int keyCode,KeyEvent event) { //Log.d("","onKeyDown++++++++++++++++++"); if (keyCode == KeyEvent.KEYCODE_BACK) { new AlertDialog.Builder(this) .setTitle(R.string.exit_tip) .setMessage(R.string.exit_message) .setNegativebutton(R.string.exit_cancel,new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog,int which) { } }) .setPositivebutton(R.string.exit_confirm,new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int whichbutton) { finish(); System.exit(0); } }).show(); return true; } else { return super.onKeyDown(keyCode,event); } }
http://www.jb51.cc/article/p-pfzezpoz-vm.html
http://www.jb51.cc/article/p-vgerwjvc-bkc.html
http://50vip.com/390.html
总结以上是内存溢出为你收集整理的cocos2dx android返回键- d出退出对话框全部内容,希望文章能够帮你解决cocos2dx android返回键- d出退出对话框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)