[英]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.