【问题标题】:alertDialogTheme not working (AppCompat v23)alertDialogTheme 不工作(AppCompat v23)
【发布时间】:2016-06-11 11:53:55
【问题描述】:

我有一个主题如下:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primaryDark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="alertDialogTheme">@style/AppTheme.Dialog</item>
</style>

<style name="AppTheme.Dialog" parent="Theme.AppCompat.Dialog.Alert">
    <item name="colorAccent">@color/accent</item>
</style>

但是,当我在应用程序中创建 AlertDialogs 时,它们根本没有主题。 ActionBar 等其他组件的颜色正确。我错过了什么吗?

我使用的是 AppCompat 版本 com.android.support:appcompat-v7:23.1.1,并且我的设备安装了 Android 4.4.4。

【问题讨论】:

  • 谢谢,我的问题是 android:alertDialogTheme 而不是 alertDialogTheme.... 经过 4 年的 android 开发,我仍然不明白为什么这会有所作为...

标签: android android-alertdialog android-appcompat android-theme


【解决方案1】:

对于遇到类似问题的任何人:请仔细检查您是否使用支持库包中的 AlertDialog.Builder,因此导入语句应如下所示:

import android.support.v7.app.AlertDialog;

在我的情况下,我导入了 android.app.AlertDialog,这导致了错误的结果。

【讨论】:

    【解决方案2】:

    创建 AlertDialog 时,您可以设置要使用的主题:

    import android.support.v7.app.AlertDialog;
    

    【讨论】:

    • 正如我在开篇文章中所说,我使用的属性alertDialogTheme应该具有相同的效果。
    猜你喜欢
    • 2015-11-26
    • 2015-11-13
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 2018-05-25
    • 1970-01-01
    相关资源
    最近更新 更多