简体   繁体   English

Android制作一个progressDialog ProgressBar不可见

[英]Android make a progressDialog ProgressBar Invisible

This is my ProgressDialog 这是我的ProgressDialog

progressBar = new ProgressDialog(Wallpapers.this);
progressBar.setCancelable(false);
progressBar.setMessage("Downloading " + downloadedFile + ".png");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.setButton(DialogInterface.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
    }
});

progressBar.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
    }
});
progressBar.show();

Given that i can force the Buttons to become VISIBLE INVISIBLE GONE with the following: 鉴于以下情况,我可以强制Buttons变为可见不可见:

progressBar.getButton(ProgressDialog.BUTTON_POSITIVE).setVisibility(View.INVISIBLE);

I had hoped to be able to do the same with the ProgressBar, this would allow more room for text to describe which button to press after the task is completed. 我希望能够对ProgressBar进行相同的操作,这将为文本提供更多空间来描述任务完成后要按哪个按钮。

But the following is my best guess and its creating a NullPointer 但是以下是我的最佳猜测,并创建了一个NullPointer

progressBar.getButton(ProgressDialog.STYLE_HORIZONTAL).setVisibility(View.INVISIBLE);

Please note I am not looking to close the Dialog, only force the ProgressBar to be Invisible. 请注意,我不是要关闭对话框,而只是将ProgressBar强制为不可见。

If it cannot be done then so be it, but any help would be great 如果无法完成,那就这样,但是任何帮助都会很棒

ProgressDialog.STYLE_HORIZONTAL and ProgressDialog.STYLE_SPINNER are not Buttons, nor are they identifiers for Buttons in the AlertDialog class. ProgressDialog.STYLE_HORIZONTALProgressDialog.STYLE_SPINNER既不是Button,也不是AlertDialog类中Button的标识符。

If you really want to stick with a ProgressDialog , you could hack your way around it by getting a View within the dialog (eg a Button or the View that has focus via getCurrentFocus() ), then get the root View of the Dialog and traverse it's children until you find a ProgressBar . 如果您真的想坚持使用ProgressDialog ,则可以通过在对话框中获取一个View(例如Button或通过getCurrentFocus()获得焦点的View)来解决问题,然后获取Dialog的根View并遍历在找到ProgressBar之前是孩子。 I wouldn't recommend this. 我不推荐这个。

A better alternative would be to create your own layout that includes a ProgressDialog , and set that as an AlertDialog's View with setView() . 更好的选择是创建自己的包含ProgressDialog的布局,并使用setView()将其设置为AlertDialog的View。 This way you can define your own ID for the bar and retrieve it via the Dialog's findViewById() method. 这样,您可以为栏定义自己的ID,并通过Dialog的findViewById()方法检索它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM