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

I want to reference the java static variable in my styles.xml, is this possible? Here's an example pseudo-xml:

<style name="Artwork">
    <item name="android:background">@drawable/border_{Constants.MY_COLOR}</item>
</style>
+2
source share
1 answer

It's impossible. The styles.xml styles are compiled into a block of data available to your application, and there is no provision for cross-referencing Java elements during assembly or runtime.

However, you can programmatically change the background color of the corresponding elements at runtime, as they are pumped up in your Java class.

+2
source

All Articles