2017-06-14 47 views
2

我試圖啓用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

注:ProgressDialog現在deprecated API-26

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

+0

這是一個更好的回答 –

0

我設法做到這一點的方式如下:

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

供參考:即SET按鈕方法已自API 3棄用,使用接受的'int'('whichButton')作爲第一個參數 – SushiHangover

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

的SET按鈕方法這是Java。我問的是Xamarin/C#。 –