您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx 安卓返回键的监听

2014-09-24 15:38 260 查看
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener(){

@Override

public void onClick(DialogInterface dialog, int which){

switch (which){

case DialogInterface.BUTTON_POSITIVE:

android.os.Process.killProcess(android.os.Process.myPid());

break;

case DialogInterface.BUTTON_NEGATIVE:

break;

default:

break;

}

}

};

public void doGameExit(){

AlertDialog isExit = new AlertDialog.Builder(s_instance).create();

isExit.setTitle("英雄战队");

isExit.setIcon(R.drawable.icon);

isExit.setMessage("你确定要退出游戏吗?");

isExit.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);

isExit.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", listener);

isExit.show();

}

@Override

public boolean dispatchKeyEvent(KeyEvent event) {

if (event.getKeyCode() == KeyEvent.KEYCODE_BACK

&& event.getAction() == KeyEvent.ACTION_DOWN

&& event.getRepeatCount() == 0) {

//具体的操作代码

doGameExit();

}

return super.dispatchKeyEvent(event);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: