在进度对话框

时间:2017-06-14 05:04:36

标签: android xamarin xamarin.android progressdialog

我正在尝试在Xamarin Android的ProgressDialog上启用“取消”按钮,但它不会出现。

这是我到目前为止所做的事情:

ProgressDialog progressDialog = new ProgressDialog(Context);
progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);
progressDialog.SetCancelable(true);

progressDialog.CancelEvent += (o, e) =>
{
    // Cancel download
};

progressDialog.Show();

相关问题:How to set cancel button in Progress Dialog?Android ProgressDialog can't add Cancel button

3 个答案:

答案 0 :(得分:5)

注意:ProgressDialog现在是API-26中的deprecated

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();

enter image description here

答案 1 :(得分:0)

我设法通过以下方式完成:

progressDialog.SetButton("Cancel", new EventHandler<DialogClickEventArgs>(
    (s, args) => { 
        // Cancel download
    }
));

答案 2 :(得分:0)

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();