小编Mar*_*arc的帖子

Android使用自定义主题来修改样式属性

我想创建两个主题,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>
Run Code Online (Sandbox Code Playgroud)

但是我有一种用于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>
Run Code Online (Sandbox Code Playgroud)

我一直在寻找一个优雅的解决方案,但一直找不到任何东西.想法?

android android-theme android-styles

5
推荐指数
1
解决办法
1722
查看次数

标签 统计

android ×1

android-styles ×1

android-theme ×1