سؤال

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

هل كانت مفيدة؟

المحلول

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>

نصائح أخرى

Create a colors.xml file in res/values. Inside that document, create your color variables.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <color name="textColorPrimary">#ffffff</color>

</resources>

Reference your colors with @colors/textColorPrimary

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top