Kid24
Kid24

Reputation: 4471

How to access style.xml values

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

Answers (3)

Anup Rojekar
Anup Rojekar

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

2red13
2red13

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

Kid24
Kid24

Reputation: 4471

The answer is here how to get Theme attributes values

Upvotes: 3

Related Questions