[英]Add cancel button on progress dialog
我正在尝试在Xamarin Android中的ProgressDialog
上启用“取消”按钮,但它不会出现。
这就是我到现在所做的:
ProgressDialog progressDialog = new ProgressDialog(Context);
progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);
progressDialog.SetCancelable(true);
progressDialog.CancelEvent += (o, e) =>
{
// Cancel download
};
progressDialog.Show();
注意:现在API-26中deprecated
ProgressDialog
var progress = new ProgressDialog(this);
progress.SetTitle("Syncing Events");
progress.Indeterminate = false;
progress.SetProgressStyle(ProgressDialogStyle.Horizontal);
progress.Max = totalEvents;
progress.Progress = currentEvent;
progress.SetButton(-3, "CancelLeft", (sender, e) => {
Log.Debug("SO", "Cancel");
});
progress.SetButton(-2, "CancelMiddle", (sender, e) =>
{
Log.Debug("SO", "Cancel");
});
progress.SetButton(-1, "CancelRight", (sender, e) =>
{
Log.Debug("SO", "Cancel");
});
progress.Show();
我设法通过以下方式实现:
progressDialog.SetButton("Cancel", new EventHandler<DialogClickEventArgs>(
(s, args) => {
// Cancel download
}
));
ProgressDialog myDialog = new ProgressDialog(YourActivity.this);
myDialog.setMessage("Loading...");
myDialog.setCancelable(false);
myDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
myDialog.show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.