Reputation: 37633
I have this XML in my res/drawable directory:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<shape android:shape="rectangle" >
<corners android:radius="10dip" />
<stroke android:width="1dip" android:color="#706969" />
<gradient android:angle="-90" android:startColor="#117e7a7a" android:endColor="#BB7e7a7a" />
</shape>
</item>
</selector>
I want to put in android:startColor="#117e7a7a"
a reference to a variable instead of a color value. ¿How can be that done? I can't find any info about that in google
Thanks
Upvotes: 0
Views: 3288
Reputation: 9450
Here is explained how resources (such as color) can be referred to from other resources/layouts.
In short, use :
android:startColor="@color/myColor" ...
where "myColor" could be defined in values/colors.xml as :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="myColor">#117e7a7a</color>
.... more colors
</resources>
Upvotes: 2
Reputation: 5551
Create a colors.xml
file in res/values
. Inside that document, create your color variables.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="textColorPrimary">#ffffff</color>
</resources>
Reference your colors with @colors/textColorPrimary
Upvotes: 2