我在Android应用程序中工作,并使用DialogFragment显示对话框,我想使DialogFragment不可取消.我已将对话框cancelable属性设置为false,但仍然没有影响.
请查看我的代码并建议我一个解决方案.
public class DialogTest extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return super.onCreateDialog(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_test, container, true);
getDialog().requestWindowFeature(STYLE_NO_TITLE);
getDialog().setCancelable(false);
return view;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个可以创建并弹出DialogFragment的Fragment,但是当我点击后退按钮时,即使我显式调用setCancelable(false),它也会取消对话框; 我的DialogFragment有没有办法对后退按钮不敏感?
public class LoadingDialogFragment extends DialogFragment
{
String title;
String msg;
public LoadingDialogFragment()
{
this.title = "Loading...";
this.msg = "Please wait...";
}
public LoadingDialogFragment(String title, String msg)
{
this.title = title;
this.msg = msg;
}
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState)
{
final ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setTitle(title);
dialog.setMessage(msg);
dialog.setIndeterminate(true);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
return dialog;
}
}
Run Code Online (Sandbox Code Playgroud)
我从AsyncTask创建DialogFragment:
private class GpsTask extends AsyncTask<String, Integer, Integer>
{
//ProgressDialog dialog;
@Override
protected void onPreExecute()
{
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
DialogFragment newFragment …Run Code Online (Sandbox Code Playgroud) android back-button fragment progressdialog android-asynctask