Cocos2dxGLSurfaceView.java public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) { switch (pKeyCode) { case KeyEvent.KEYCODE_BACK: Cocos2dxActivity.clossGame(); 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); } } Cocos2dxActivity.java import android.app.AlertDialog; import android.content.DialogInterface; import android.app.Dialog; public static void clossGame() { log.info("return!"); Cocos2dxActivity mainActivity = (Cocos2dxActivity) sContext; mainActivity.onPause(); Dialog alertDialog = new AlertDialog.Builder(mainActivity). setTitle("游戏提示"). setMessage("是否确定要退出游戏?"). setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Cocos2dxActivity mainActivity = (Cocos2dxActivity) sContext; mainActivity.finish(); System.exit(0); } }). setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Cocos2dxActivity mainActivity = (Cocos2dxActivity) sContext; mainActivity.onResume(); } }). create(); alertDialog.show(); }
import android.view.WindowManager; getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //应用运行时,保持屏幕高亮,不锁屏
时间: 2024-09-30 09:45:18