创建全局 ProgressDialog

Create global ProgressDialog

我在另一个 class 中创建了用于显示自定义进度条的通用函数。当我调用此函数时,将显示对话框,但当我想关闭该对话框时,它无法关闭。这是代码

public void showPopupProgressSpinner(Boolean isShowing) {

        Dialog progressDialog;
        ProgressBar progressBar;

        progressDialog = new Dialog(context);
        progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        progressDialog.setContentView(R.layout.popup_progressbar);
        progressDialog.setCancelable(false);
        progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        progressBar = (ProgressBar) progressDialog.findViewById(R.id.progressBar1);
        progressBar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#ff6700"),
                android.graphics.PorterDuff.Mode.MULTIPLY);

        if (isShowing == true) {
            progressDialog.show();
        } else if (isShowing == false) {

            progressDialog.dismiss();

        }
    }

我就是这样调用这个函数的

显示对话框

utils.showPopupProgressSpinner(true);

隐藏对话框

utils.showPopupProgressSpinner(false);

试试这个对我有用。

private Dialog progressDialog = null;
private ProgressBar progressBar;

public void showPopupProgressSpinner(Boolean isShowing) {
    if (isShowing == true) {
        progressDialog = new Dialog(AndroidVideoCaptureExample.this);
        progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        progressDialog.setContentView(R.layout.popup_progressbar);
        progressDialog.setCancelable(false);
        progressDialog.getWindow().setBackgroundDrawable(
                new ColorDrawable(Color.TRANSPARENT));

        progressBar = (ProgressBar) progressDialog
                .findViewById(R.id.progressBar1);
        progressBar.getIndeterminateDrawable().setColorFilter(
                Color.parseColor("#ff6700"),
                android.graphics.PorterDuff.Mode.MULTIPLY);
        progressDialog.show();
    } else if (isShowing == false) {
        progressDialog.dismiss();
    }
}

谢谢。