首页 > 解决方案 > Android RRO - 覆盖自定义属性

问题描述

在我的主要 Android 应用程序中,我定义了一个属性,它指向某种颜色。它看起来像这样:

<declare-styleable name="ThemeColors">
    <attr name="my_button_background" format="color" />
</declare-styleable>

然后我有我的风格

<style name="MyTheme">
    <item name="my_button_background">@color/color_blue</item>
</style>

之后,我像这样设置我的按钮:

<Button
    style="@style/some_style"
    android:text="@string/some_text"
    android:background="?attr/my_button_background"/>

现在,在我的叠加应用程序中,如果我做这样的事情,它可以完美运行

<color name="color_blue">#FFFF00</color>

但是,如果我想使用它来覆盖属性,它就不起作用。

<color name="my_button_background">#FFFF00</color>

color_blue另一种解决方案是用类似的东西包装color_button_background,然后将其用作我的属性的指针,并在我的 RRO 中覆盖它。但它只会带来很多混乱。而且我有很多属性,这将使这项工作更加耗时。

有人可以帮我解决这个问题吗?有没有办法覆盖属性?我尝试用谷歌搜索这个,但我没有找到解决方案。

标签: androidthemesandroid-theme

解决方案


推荐阅读