2

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.

Kid24
  • 4,401
  • 4
  • 23
  • 19

3 Answers3

3

The answer is here how to get Theme attributes values

Community
  • 1
  • 1
Kid24
  • 4,401
  • 4
  • 23
  • 19
0

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);
2red13
  • 11,197
  • 8
  • 40
  • 52
  • Sorry, but I defined my problem differently: I need to access style values from java sources programmaticaly. – Kid24 May 18 '11 at 23:06
  • 2
    I fail seeing how to do that, in my R class, the style is just a "public static final int" variable – RMalke Jan 16 '13 at 21:30
-2

I think you can use following code in order to access the style1,

style="@style1/titleColor"
style="@style1/lineColor"

That is all.

Alexander
  • 23,432
  • 11
  • 63
  • 73
Anup Rojekar
  • 1,093
  • 9
  • 29
  • Sorry, but I defined my problem differently: I need to access style values from java sources programmaticaly. – Kid24 May 18 '11 at 23:08