【问题标题】:How to display MessageBox in Monodroid如何在 Monodroid 中显示 MessageBox
【发布时间】:2013-05-21 01:14:20
【问题描述】:

如何在 Xamarin.Android 中显示消息框?如何从消息框中获得是或否的响应?

--- 更新:

myBtn.Click += (sender, e) => 
{
   new AlertDialog.Builder(this)
   .SetMessage("hi")
   .Show();
};

【问题讨论】:

    标签: c# android xamarin.android android-alertdialog


    【解决方案1】:

    您可以在Activity 中使用AlertDialog.Buider 类。

    new AlertDialog.Builder(this)
        .SetPositiveButton("Yes", (sender, args) =>
        {
            // User pressed yes
        })
        .SetNegativeButton("No", (sender, args) =>
        {
            // User pressed no 
        })
        .SetMessage("An error happened!")
        .SetTitle("Error")
        .Show();
    

    【讨论】:

    • 谢谢。有用。但是我怎样才能让它看起来像 Windows phone 中的 MessageBox 更好呢? MessageBox 具有高度、宽度和背景颜色。
    • 查看来自this答案的xml并使用来自this的构造函数之一。请注意,在 API 级别 11 之前,您必须使用 ContextThemeWrapper 为对话框设置主题,因为新的构造函数不可用。
    【解决方案2】:

    试试这个:

    public void ShowAlert (string str)
            {
                AlertDialog.Builder alert = new AlertDialog.Builder (this);
                alert.SetTitle (str);
                alert.SetPositiveButton ("OK", (senderAlert, args) => {
                    // write your own set of instructions
                    });
    
                //run the alert in UI thread to display in the screen
                RunOnUiThread (() => {
                    alert.Show ();
                });
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      • 2011-03-29
      • 1970-01-01
      相关资源
      最近更新 更多