繁体   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