dialog点击对话框之外的区域禁止取消,点击返回按钮取消对话框的同时关闭当前activity

private void showIsLoadDraftDialog(final EPrescriptionVO ePrescriptionVO){
        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setMessage("刚才的草稿还没提交,要继续开方吗?")
                .setPositiveButton("继续开方",new DialogInterface.OnClickListener(){
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("重新开方",new DialogInterface.OnClickListener(){
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        //点击返回按钮取消dialog同时直接关闭当前activity
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                ElectronPrescriptionActivity.this.finish();
            }
        });
        AlertDialog dialog = builder.create();
        //点击dialog之外的区域禁止取消dialog
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    }

你可能感兴趣的:(对话框dialog,android)