AlertDialog在Android / Mono上看起来很怪异

时间:2013-02-26 12:52:18

标签: c# android mono xamarin.android

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

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

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

然而,它看起来像这样:

enter image description here

问题:

  1. 当前视图未显示在alertdialog后面,它只是白色。
  2. 它与顶部对齐,而不是中心
  3. 主题或字体颜色错误,导致文字难以阅读。
  4. 我使用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中没有任何变化。

1 个答案:

答案 0 :(得分:0)

解决了它。使用

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

它看起来更好。我还使用了Activity.ShowDialog()并将我的AlertDialog代码放在

protected override Dialog OnCreateDialog(int id, Bundle args)

不确定它是否有任何区别。

好的博文:http://blog.ostebaronen.dk/2013/02/using-dialogs-in-mono-for-android.html