我使用的是作为Fragment
托管的ProgressDialog
。即使我将ProgressDialog
设置为不可取消,BACK按钮仍将操作以将该Fragment
从堆栈中删除。我的内部类看起来像这样:
public static class ProgressDialogFragment extends DialogFragment {
private DialogStyle dialogStyle;
public static ProgressDialogFragment newInstance(String title, String message) {
ProgressDialogFragment fragment = new ProgressDialogFragment();
Bundle args = new Bundle();
args.putString("title", title);
args.putString("message", message);
fragment.setArguments(args);
return fragment;
}
public void setDialogStyle(DialogStyle dialogStyle) {
this.dialogStyle = dialogStyle;
}
@Override
public ProgressDialog onCreateDialog(Bundle savedInstanceState) {
String title = getArguments().getString("title");
String message = getArguments().getString("message");
ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle(title);
progressDialog.setMessage(message);
if(dialogStyle!=null) {
switch (dialogStyle) {
case CANCELABLE:
progressDialog.setCancelable(true);
break;
case NON_CANCELABLE:
progressDialog.setCancelable(false);
break;
}
} else {
progressDialog.setCancelable(false);
}
progressDialog.show();
return progressDialog;
}
}
然后我公开的方法是:
public void showProgressDialog(String title, String message, DialogStyle dialogStyle) {
Fragment prev = fragmentManager.findFragmentByTag("progress dialog");
if(prev!=null) {
ft.remove(prev);
}
ft.addToBackStack(null);
DialogFragment newFragment = ProgressDialogFragment.newInstance(title, message);
((ProgressDialogFragment)newFragment).setDialogStyle(dialogStyle);
newFragment.show(fragmentManager, "progress dialog");
}
因此,这里明显的混淆是,BACK按钮删除了ProgressDialog
,因为它是作为Fragment
进行管理的。那么,我如何才能使Dialog
不可取消呢?
尝试像这样的东西似乎很奇怪:
@Override
public void onBackPressed() {
if(fragmentManager.fragmentManager.findFragmentByTag("progress dialog")!=null) {
}
}
发布于 2011-09-08 02:15:20
为什么不在DialogFragment上试用setCancelable(false)
而不是ProgressDialog呢?
发布于 2014-02-21 17:08:46
您还可以在ProgressDialog
上使用setCancelable(false)
https://stackoverflow.com/questions/7338199
复制相似问题