将多个样式项目设置为xml中的相同值

问题描述:

我正在研究一个包含多个主题的项目,并且每个主题都具有不同的属性值。将多个样式项目设置为xml中的相同值

我想我的一些属性是相同的价值,我知道我可以做到这一点。

<style name="theme_plain" parent="AppBaseThemeLight"> 
    <item name="theme_backgroundtint">#FFF1F1F1</item> 
    <item name="theme_previewboxcolor">?theme_backgroundtint</item> 
</style> 

在我的代码,然后访问与

int boxcol = getIntFromAttr(R.attr.theme_previewboxcolor, themecolor); 

这个值在当前主题设置应用程序是有问题的主题,这种方法效果很好,和theme_previewboxcolor = theme_backgroundtint从价值相同的主题。

但是,当前设置的主题是不同的主题时,theme_previewboxcolor会将theme_backgroundtint的值作为当前设置的主题。我明白这是为什么,因为theme_backgroundtint的当前值被设置为当前主题的值。

我需要一种方法来有theme_previewboxcolor匹配这是在同一个主题设置theme_backgroundtint的价值,所以,即使在当前的一组主题是不同的,如在设置theme_previewboxcolor的价值和theme_backgroundtint的价值主题是一样的。

感谢

+0

仅仅使用引用的颜色有什么问题:@ color/almost_white? – FunkTheMonk

+0

问题是我有多个不同的子主题,所以在父类中,我想将theme_previewboxcolor设置为theme_backgroundtint,以便即使当theme_backgroundtint随后在子主题中被重写时也是如此,就像您可以使用属性一样,所以绝对颜色参考不起作用 – Luke

我已经找到了变通,在这里我用枚举来指定哪些属性值应该在我的代码theme_previewboxcolor读取。但是,这不允许theme_previewboxcolor交替声明新值。