开发者

Can I use a static variable from a Java class in res/values/styles.xml?

开发者 https://www.devze.com 2022-12-27 03:51 出处:网络
I want to refer to a static Java variable in my styles.xml, is that possible?Here\'s a pseud开发者_Python百科o-xml example:

I want to refer to a static Java variable in my styles.xml, is that possible? Here's a pseud开发者_Python百科o-xml example:

<style name="Artwork">
    <item name="android:background">@drawable/border_{Constants.MY_COLOR}</item>
</style>


This isn't possible. The styles.xml is compiled into a block of data available to your app, and there is no provision whatsoever to cross-reference Java elements at build or runtime.

However you will be able to programatically modify the background color of the relevant elements at runtime as they are inflated in your Java class.

0

精彩评论

暂无评论...
验证码 换一张
取 消