我想显示一个进度对话框,该对话框仅在需要时显示“关闭”按钮,例如当进度值达到其最大值时。在那个“关闭”按钮上,我想要关闭对话框。我使用否定按钮进行了进度对话,当用户点击它时我可以忽略它但我不希望“关闭”按钮在我想要或完成进度时始终可见/启用。
感谢。
答案 0 :(得分:5)
为了建立Guillaume的评论和Karim的答案,您可以隐藏/显示或启用/禁用ProgressDialog上的按钮,如下所示:
ProgressDialog dlg = new ProgressDialog(this);
dlg.setButton(ProgressDialog.BUTTON_NEUTRAL,
"Close",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//button click stuff here
}
});
dlg.show();
dlg.getButton(ProgressDialog.BUTTON_NEUTRAL).setEnabled(false);
//or alternatively
//dlg.getButton(ProgressDialog.BUTTON_NEUTRAL).setVisibility(View.INVISIBLE);
一旦任务完成,您可以挂在Button
上以便稍后启用。致电getButton
后,请务必致电show
。
答案 1 :(得分:1)
您应该使用ProgressBar和Button构建自定义对话框。然后使用Button.setVisibility(View.VISIBLE)和Button.setVisibility(View.INVISIBLE)