簡體   English   中英

在進度對話框中添加取消按鈕

[英]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();

相關問題: 如何在進度對話框中設置取消按鈕? Android ProgressDialog無法添加取消按鈕

注意:現在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM