alertDialogTheme 不工作(AppCompat v23)
alertDialogTheme not working (AppCompat v23)
我的主题是这样的:
<!-- 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。
创建 AlertDialog 时,您可以设置要使用的主题:
import android.support.v7.app.AlertDialog;
对于遇到类似问题的任何人:请仔细检查您使用的是支持库包中的 AlertDialog.Builder,因此导入语句应如下所示:
import android.support.v7.app.AlertDialog;
在我的例子中,我导入了 android.app.AlertDialog
,这导致了错误的结果。
我的主题是这样的:
<!-- 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。
创建 AlertDialog 时,您可以设置要使用的主题:
import android.support.v7.app.AlertDialog;
对于遇到类似问题的任何人:请仔细检查您使用的是支持库包中的 AlertDialog.Builder,因此导入语句应如下所示:
import android.support.v7.app.AlertDialog;
在我的例子中,我导入了 android.app.AlertDialog
,这导致了错误的结果。