创建全局ProgressDialog

时间:2016-02-25 06:41:46

标签: android dialog alertdialog android-alertdialog progressdialog

我创建了用于在另一个类中显示自定义进度条的常用功能。当我调用此功能时,将显示对话框,但是当我想要关闭该对话框时,它不会被解雇。这是代码

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);

1 个答案:

答案 0 :(得分:1)

试试这个对我有用。

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();
    }
}

感谢。