VectorDrawable: Invalid Drawable Tag Gradient
Solution 1:
This solution is working for us
in build.gradle
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
and use app:srcCompat
instead of android:src
when setting a vector drawable with gradient to a ImageView
.
Solution 2:
The property android:fillColor is only supported in OS 7.0+ ,
android:fillColor Specifies the color used to fill the path. May be a color or, for SDK 24+, a color state list or a gradient color (See GradientColor and GradientColorItem). If this property is animated, any value set by the animation will override the original value. No path fill is drawn if this property is not specified.
for older versions in directory /drawable we can place the vector asset without the gradients, for example:
<vector android:height="24dp" android:viewportHeight="651.95"
android:viewportWidth="531.48" android:width="24dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:pathData="M386.8,30.2c-48.5,0 -76.1,18 -121.1,18s-72.6,-18 -121.1,-18c-87.9,0 -144.7,83.3 -144.7,186 0,92.9 160,350.5 265.7,350.5 112.9,0 265.7,-257.6 265.7,-350.5C531.5,113.5 474.7,30.2 386.8,30.2Z">
<!--<aapt:attr name="android:fillColor">
<gradient android:endX="212457.73219299316"
android:endY="440836.2612554932"
android:startX="212457.73219299316"
android:startY="92857.94223999024" android:type="linear">
<item android:color="#FFFC3A11" android:offset="0.0"/>
<item android:color="#FFDA0300" android:offset="1.0"/>
</gradient>
</aapt:attr>-->
</path>
...
...
and inside /drawable-24 directory with gradients:
<vector android:height="24dp" android:viewportHeight="651.95"
android:viewportWidth="531.48" android:width="24dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:pathData="M386.8,30.2c-48.5,0 -76.1,18 -121.1,18s-72.6,-18 -121.1,-18c-87.9,0 -144.7,83.3 -144.7,186 0,92.9 160,350.5 265.7,350.5 112.9,0 265.7,-257.6 265.7,-350.5C531.5,113.5 474.7,30.2 386.8,30.2Z">
<aapt:attr name="android:fillColor">
<gradient android:endX="212457.73219299316"
android:endY="440836.2612554932"
android:startX="212457.73219299316"
android:startY="92857.94223999024" android:type="linear">
<item android:color="#FFFC3A11" android:offset="0.0"/>
<item android:color="#FFDA0300" android:offset="1.0"/>
</gradient>
</aapt:attr>
</path>
...
...
Solution 3:
android:fillColor with gradient only is support for API 24+ (7.0)
ref: https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html
try add in 'drawable-v24' and the same vector in 'drawable' folder without gradient
Solution 4:
The error caused by android:fillColor attribute; this because:
android:fillColor Specifies the color used to fill the path. May be a color or, for SDK 24+, a color state list or a gradient color (See GradientColor and GradientColorItem). If this property is animated, any value set by the animation will override the original value. No path fill is drawn if this property is not specified.
If you want use gradient in version older than 24 you can use a workaround:
-Edit your vector (called for example as drawable/ic_vector.xml):
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="360dp"
android:height="110dp"
android:viewportWidth="360.0"
android:viewportHeight="110.0">
<path
android:pathData="M82,46H0v64h360V46h-81.88v-0.3h-26.21c-14.25,0 -38.69,-6.2 -46.95,-25.93C200.99,10.25 193.27,0.52 180,0.47c-13.27,-0.05 -20.04,9.24 -24.75,19.3 -8.22,17.55 -24.66,26.19 -49.34,25.93H82V46z"
android:fillType="evenOdd">
<!--<aapt:attr name="android:fillColor">
<gradient
android:startY="0.41999998688697815"
android:startX="0.0"
android:endY="110.0"
android:type="linear"
android:endX="360.0">
<item android:offset="0.0" android:color="#FFCB09FF" />
<item android:offset="1.0" android:color="#FF8A06FF" />
</gradient>
</aapt:attr></path>-->
-Create another drawable resource where insert gradient as item:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="#FFCB09FF"
android:endColor="#FF8A06FF"
android:angle="270">
</gradient>
</shape>
</item>
<item android:drawable="@drawable/ic_vector"/>
Hope I have helped you!
Solution 5:
I was able to fix this by using
app:srcCompat="@drawable/ic_vector"
instead of
android:src="@drawable/ic_vector"
This was tested on API 22 device
Post a Comment for "VectorDrawable: Invalid Drawable Tag Gradient"