v19/v21中的重复样式 [英] Repeating style in v19/v21

查看:58
本文介绍了v19/v21中的重复样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的styles.xml中有这个:

<style name="UserTheme" parent="ThemeBase">
    <item name="android:editTextStyle">@style/EditTextTheme</item>
</style>

为什么必须在v19/styles.xmlv21/styles.xml中重复editTextStyle行.

Why do I have to repeat the editTextStyle line in v19/styles.xml and v21/styles.xml.

v21/styles.xml:

<style name="UserTheme" parent="ThemeBase">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:editTextStyle">@style/EditTextTheme</item>
</style>

有没有一种方法可以只在主styles.xml中调用它并将其应用于所有地方,所以我不必多次编写它?

Is there a way to just call it in the main styles.xml and have it apply everywhere so I don't have to write it multiple times?

推荐答案

我找不到任何推荐的解决方案,因此我研究了AppCompat的源代码.他们这样做的方式就是这样.

I couldn't find any recommended solution so I i digged into AppCompat source. The way they do it is like this.

在您的styles.xml中

In your styles.xml

    <style name="Base.V7.Theme.YourThemeName" parent="Theme.AppCompat.Light.NoActionBar">
    </style>

    <style name="Base.Theme.YourThemeName" parent="Base.V7.Theme.YourThemeName" />

    <style name="Theme.YourThemeName" parent="Base.Theme.YourThemeName" >
       <item name="colorPrimary">@color/primary</item>
       <item name="colorPrimaryDark">@color/primary_dark</item>
       <item name="colorAccent">@color/accent</item>
    </style>

以您的styles-v21.xml

In your styles-v21.xml

    <style name="Base.V21.Theme.YourThemeName" parent="Base.V7.Theme.YourThemeName">
       <item name="android:navigationBarColor">@color/white</item>
       <item name="android:windowTranslucentStatus">true</item>
    </style>
    <style name="Base.Theme.YourThemeName" parent="Base.V21.Theme.YourThemeName" />

以您的styles-v22.xml

In your styles-v22.xml

    <style name="Base.V22.Theme.YourThemeName" parent="Base.V21.Theme.YourThemeName">
       <item name="android:navigationBarColor">@color/black</item>
       <item name="android:windowTranslucentStatus">false</item>
    </style>
    <style name="Base.Theme.YourThemeName" parent="Base.V22.Theme.YourThemeName" />

对于每个新版本,您都扩展了先前的基本版本.如果要覆盖不同版本的任何属性,只需将其放在新的styles-vXX.xml文件的Base.VXX.Theme.YourThemeName块中.

For every new version you extend the previous base version. If you want to override any attribute for different version just put it inside Base.VXX.Theme.YourThemeName block on your new styles-vXX.xml file.

这篇关于v19/v21中的重复样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆