开发者

2 Colors Defined In XML - Is It Possible In XML Code For One Color To Refer To The Other?

Say for example I define 3 colours in XML code:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="red">#af0000</color>
    <color name="green">#00af00</color>
    <color name="blue">#0092ed</color>
</resources>

Now I want to add a fourth colour which I will call 'selected_colour' and I want its value to be one of the three colours I have already defined in XML, AND I want to define this assignment in XML开发者_JAVA百科. Is this possible?


As far as I know, you cannot do such thing and change its value dynamically. Instead set a static Color object in which you set the current selected color and use it whenever you want.


Try this:

<color name="selected_colour">@resource/red</color>

You may have to repalce @resource with something else, but the idea itself should work.


<?xml version="1.0" encoding="utf-8"?> <resources> 
<color name="red">#af0000</color> 
<color name="green">#00af00</color>
<color name="blue">#0092ed</color> </resources>  <options>  <selectedColor name="red" />  </options>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜