C# 如何在 Monodroid 中显示 MessageBox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16660632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:36:17 来源:igfitidea点击:
How to display MessageBox in Monodroid
提问by MilkBottle
How can I display a message box in Xamarin.Android? How can I get the yes or no response from the message box?
如何在 Xamarin.Android 中显示消息框?如何从消息框中获得是或否响应?
--- Updated :
- - 更新 :
myBtn.Click += (sender, e) =>
{
new AlertDialog.Builder(this)
.SetMessage("hi")
.Show();
};
回答by Alex Wiese
You can use the AlertDialog.Buiderclass from within an Activity.
您可以AlertDialog.Buider从Activity.
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();
回答by Ram Ch. Bachkheti
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 ();
});
}

