Reputation: 4471
I have styles.xml with Style definition like this:
<style name="Style1">
<item name="titleColor">@color/red</item>
<item name="lineColor">@color/light_red</item>
</style>
I'd like to access "titleColor", "lineColor" attributes values programmaticaly. Is it possible somehow to do? Would appreciate your help very much, cause already spend hours trying to find a solution.
Upvotes: 2
Views: 3177
Reputation: 1103
I think you can use following code in order to access the style1,
style="@style1/titleColor"
style="@style1/lineColor"
That is all.
Upvotes: -2
Reputation: 11217
Yes, do it like that:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Style1">
<item name="titleColor">@color/red</item>
<item name="lineColor">@color/light_red</item>
</style>
</resources>
Then Build the Project, after Building you can access the values with
R.style.Style1...
edit to clarify:
button1.setBackgroundColor(R.style.Style1.titleColor);
Upvotes: 0