How to show the SecondaryProgress in a Android Pro

2019-09-03 09:54发布

问题:

I need to show the secondary progress of a ProgressDialog on Android, but it shows only the first progressbar in the dialog.

This is the code I use:

progress = new ProgressDialog(this);
    progress.setIndeterminate(false);
    progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progress.setProgress(25);

    progress.setSecondaryProgress(10);

    progress.show();

回答1:

That seems to have no effect if set before the dialog is shown.

Try:

final ProgressDialog progress = new ProgressDialog(this);

progress.setIndeterminate(false);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

progress.setOnShowListener(new OnShowListener() {   

    public void onShow(DialogInterface dialog) {
        progress.setProgress(50);
        progress.setSecondaryProgress(75);
    }
});

progress.show();

EDIT