cocos2dx 安卓返回键的监听

来源:互联网 发布:csgo弹道优化参数存放 编辑:程序博客网 时间:2024/06/03 14:44

 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);
    }
0 0
原创粉丝点击