Xamarin.Android
ダイアログ
サーチ…
備考
ダイアログのContextを設定する
ActiviyからDialogを作成するときに、 thisをコンテキストとして使用できます。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Fragmentsでは、プロパティContextを使用します。
AlertDialog.Builder builder = new AlertDialog.Builder(Context);
ボタンの種類
SetNeutralButton()は、通知が読み取られるという簡単な通知と確認に使用できます。 SetPositiveButton()は、たとえば「このアイテムを削除しますか?」などの確認に使用できます。 SetNegativeButton()は、ダイアログをSetNegativeButton()アクションをキャンセルするためのものです。
戻るボタンからキャンセルを無効にする
戻るボタンでダイアログをSetCanceable(false)ことができないようにしたい場合は、 SetCanceable(false)呼び出すことができます。これは、戻るボタンでのみ機能します。
回転
ダイアログが表示されている間に画面を回転させると、画面は消え、okアクションとcancelアクションは呼び出されません。アクティビティーの内部でこれを処理し、アクティビティーがリロードされた後にダイアログを再表示する必要があります。
これを回避するには、代わりにDialogFragmentを使用します。
警告ダイアログ
アラートダイアログの作成
AlertDialog.Builder builder = new AlertDialog.Builder(Context);
builder.SetIcon(Resource.Drawable.Icon);
builder.SetTitle(title);
builder.SetMessage(message);
builder.SetNeutralButton("Neutral", (evt, args) => {
// code here for handling the Neutral tap
});
builder.SetPositiveButton("Ok", (evt, args) => {
// code here for handling the OK tap
});
builder.SetNegativeButton("Cancel", (evt, args) => {
// code here for handling the Cancel tap
});
builder.SetCancelable(false);
builder.Show();
Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow