1

我正在使用此代码在网络错误上显示 AlertDialog:

var builder = new AlertDialog.Builder(this);
builder.SetMessage(error);

builder.SetCancelable(false);
builder.SetPositiveButton("OK", delegate { });
builder.Show();

但是,它看起来像这样:

在此处输入图像描述

问题:

  1. 当前视图不显示在警报对话框后面,它只是白色的。
  2. 它与顶部对齐,而不是中心
  3. 主题或字体颜色错误,使文本难以阅读。

我使用 Theme.DeviceDefault.Light 作为活动的主题:

[Activity (Label = "xxx", Theme = "@style/MyAppTheme", MainLauncher = true)]

...

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light">
   </style>
</resources>

如何解决这个问题?已尝试将 MyAppTheme 作为第二个参数插入,AlertDialog.Builder(this, Resource.Style.MyAppTheme)但 UI 没有变化。

4

1 回答 1

0

Solved it. Used

var builder = new AlertDialog.Builder(this, Android.App.AlertDialog.ThemeHoloLight);

and it looks better. I also used Activity.ShowDialog() and placed my AlertDialog code inside

protected override Dialog OnCreateDialog(int id, Bundle args)

not sure that it did any difference.

Good blogpost: http://blog.ostebaronen.dk/2013/02/using-dialogs-in-mono-for-android.html

于 2013-02-27T11:45:25.310 回答