【发布时间】:2015-04-08 20:18:03
【问题描述】:
我想创建两个主题,GrayTheme 和 RedTheme,它们修改一个样式属性。例如这是我的两个主题,默认字体颜色是白色,这对两个主题都很好:
<style name="RedTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
<style name="GrayTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
但我有一种用于 Header TextViews 的样式。如果我使用 RedTheme,我希望 HeaderFont 样式的 textColor 为红色,如果是 GrayTheme,我希望 HeaderFont textColor 为灰色,而无需修改访问此 HeaderFont 样式的各个 xml 文件。
<style name="HeaderFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/gray</item>
</style>
我一直在寻找一个优雅的解决方案,但没有找到任何东西。想法?
【问题讨论】:
标签: android android-theme android-styles