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);
}
@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);
}
相关文章推荐
- Cocos2dx 3.2键盘监听的打开方式以及点击两次返回退出的实现方法
- 安卓学习笔记---Fragment 里面加webview 监听onback事件(WebView的返回以及整个退出事件)
- 监听安卓返回键
- 安卓端如何监听系统返回键按钮
- 监听浏览器返回事件,安卓返回事件
- Cocos2dx 3.2键盘监听的打开方式以及点击两次返回退出的实现方法
- activity继承Cocos2dxActivity后无法监听安卓返回按键
- cocos2dx中调用Andriod中的返回键和菜单监听
- 安卓之关于监听home键返回桌面的总结
- Cocos Creator 监听安卓屏幕下方返回键
- 安卓返回键监听:退出程序
- 安卓奇葩问题之:返回按键监听,使Dialog不消失
- cordova 安卓 android 物理 返回键 监听和处理
- 安卓开发中监听手机返回键,让点击2次退出
- 【cocos2dx】监听安卓机的返回键
- 安卓重写系统返回键,以及如何监听弹出框的系统返回键
- H5+APP监听安卓物理返回键
- 返回按键监听-Quick-Cocos2dx
- cocos2dx 监听Android返回键、菜单键等
- cocos2dx 中如何实现安卓返回按键的反馈