简体   繁体   English

如何在Monodroid中显示MessageBox

[英]How to display MessageBox in Monodroid

How can I display a message box in Xamarin.Android? 如何在Xamarin.Android中显示消息框? How can I get the yes or no response from the message box? 如何从消息框中获得是或否的响应?

--- Updated : - - 更新 :

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

You can use the AlertDialog.Buider class from within an Activity . 您可以在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();

Try this: 试试这个:

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 ();
            });
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM