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

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

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

Screenshot_2013-07-19-13-04-00
很簡單我就不贅述,基本上透過 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<Button>(Resource.Id.btn1);
 
            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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值