[Xamarin] 簡單使用AlertDialog (转帖)

這東西跟Toast 很像,有方便提示的作用

像是Windows 上面的MessageBox 或是 Javascript 的 Alert 會先阻斷使用者並且下一個決定


很簡單我就不贅述,基本上透過 AlertDialog 就可以輕鬆叫起來

using System;
 
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
 
namespace TestDialog
{
    [Activity(Label = "TestDialog", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        int count = 1;
 
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
 
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
 
            var btn1 = FindViewById
 
            btn1.Click += delegate
                {
                    var alertDialog1 = new AlertDialog.Builder(this).Create();
                    // 設定Title
                    alertDialog1.SetTitle("警告視窗TITLE");
                    // 內文
                    alertDialog1.SetMessage("Hello , 我是內文");
                    alertDialog1.SetIcon(Resource.Drawable.Icon);
                    //第一顆按鈕
                    alertDialog1.SetButton("OK", (sender, args) => Toast.MakeText(this, "OK被按下了", ToastLength.Short).Show());
                    //第二顆按鈕
                    alertDialog1.SetButton2("取消", (sender, args) => Toast.MakeText(this, "取消被按下了", ToastLength.Short).Show());
                    alertDialog1.Show();
 
                };
        }
    }
}
 

因為很簡單所以就沒多加解釋了.. reference:  http://developer.android.com/guide/topics/ui/dialogs.html
http://developer.android.com/reference/android/app/AlertDialog.html

转载于:https://www.cnblogs.com/whatthehell/p/3444752.html

你可能感兴趣的:([Xamarin] 簡單使用AlertDialog (转帖))