在Android中,在启动活动之前显示进度对话框的方法如下:
public class ProgressDialogFragment extends DialogFragment {
public static ProgressDialogFragment newInstance() {
ProgressDialogFragment fragment = new ProgressDialogFragment();
return fragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setMessage("正在加载,请稍候...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
return dialog;
}
}
private void showProgressDialog() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ProgressDialogFragment progressDialogFragment = ProgressDialogFragment.newInstance();
progressDialogFragment.show(fragmentTransaction, "progress_dialog");
}
private void dismissProgressDialog() {
FragmentManager fragmentManager = getSupportFragmentManager();
ProgressDialogFragment progressDialogFragment = (ProgressDialogFragment) fragmentManager.findFragmentByTag("progress_dialog");
if (progressDialogFragment != null) {
progressDialogFragment.dismiss();
}
}
showProgressDialog()
方法,在需要关闭进度对话框的地方调用 dismissProgressDialog()
方法。推荐的腾讯云相关产品:
产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云