android - AlertDialog 的 setCancelable(false) 方法不起作用

标签 android android-alertdialog

我创建了一个运行良好的 AlertDialog。它正在消失,如果我按下:
1) 转义键盘按钮或
2) 使用鼠标返回按钮
为了使其即使在上述条件下也能保持专注,我在构建时添加了“.setCancelable(false)”语句。但是,我仍然看到对话框消失。问题出在哪里? 请帮忙。

添加代码:

return new AlertDialog.Builder(getActivity())
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(title)
                .setCancelable(false)
                .setPositiveButton(R.string.alert_dialog_ok,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ((FragmentAlertDialog)getActivity()).doPositiveClick();
                        }
                    }
                )
                .setNegativeButton(R.string.alert_dialog_cancel,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ((FragmentAlertDialog)getActivity()).doNegativeClick();
                        }
                    }
                )
                .create();


环境:XP Professional 上的 Android 4.0。

最佳答案

this你的完整代码?那么请更改您的代码以像这样设置 setCancelable(false)

void showDialog() {
    DialogFragment newFragment = MyAlertDialogFragment.newInstance(
            R.string..alert_dialog_two_buttons_title);
    newFragment.setCancelable(false);
    newFragment.show(getFragmentManager(), "dialog");
}

关于android - AlertDialog 的 setCancelable(false) 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8906269/

相关文章:

java - android-哪个线程在SensorChanged上运行?

java - 如何在 Alert Dialog Builder 中将文本居中?

android - 从服务启动时对话框 Activity 打开两次

android - RatingBar 自定义每个评级元素的大小增加

android - 如何使用 Android 的联系人对话框选择电话号码

java - Android加载图片到ListView AsyncTask

android - 如何处理关闭 RadioButtonDialog

android - Alertdialog 即使在关闭后也会弹出

android - 使用拆分字符串在警报对话框中获取选定的列表项

android - WindowManager 中 View 的 onConfigurationChanged 工作不可靠