开发者

How to access style.xml values

开发者 https://www.devze.com 2023-03-06 21:37 出处:网络
I have styles.xml with Style definition like this: <style name=\"Style1\"> <item name=\"titleColor\">@color/red</item>

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 val开发者_如何学Pythonues programmaticaly. Is it possible somehow to do? Would appreciate your help very much, cause already spend hours trying to find a solution.


The answer is here how to get Theme attributes values


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);


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

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

That is all.

0

精彩评论

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