如何在Xamarin.Android中显示消息框?我如何从消息框中获取是或否的响应?
--- 更新:
myBtn.Click += (sender, e) =>
{
new AlertDialog.Builder(this)
.SetMessage("hi")
.Show();
};
如何在Xamarin.Android中显示消息框?我如何从消息框中获取是或否的响应?
--- 更新:
myBtn.Click += (sender, e) =>
{
new AlertDialog.Builder(this)
.SetMessage("hi")
.Show();
};
您可以在Activity
内使用AlertDialog.Builder
类。
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();
试试这个:
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 ();
});
}
ContextThemeWrapper
来为对话框设置主题,因为较新的构造函数不可用。 - Alex Wiese