i downloaded a svg icon from font awesome for an app in android, when i create a vector asset i import my svg, but when i trie to compile this give me the following error
error: 'currentColor' is incompatible with attribute fillColor (attr) color.
i tried to change directly the fillcolor, but when i compile the app, this remake the xml and put again the word "current color"
this is the xml that vector asset generate
<vector android:autoMirrored="true" android:height="512dp"
android:viewportHeight="512" android:viewportWidth="448"
android:width="448dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="currentColor" android:pathData="..."/>
</vector>
how i can fix it?
android:fillColor must be a color (current is string)
Change android:fillColor="currentColor" to color hex ex:
android:fillColor="#00FFFF"
or reference colors.xml as:
android:fillColor="@colors/colorPrimary"
or an other way (if set as below, the color will change by theme):
android:fillColor="?colorPrimary"
.svg files downloaded from font awesome have the color set to "currentColor". When creating the vector asset, android imports the color from the original file. Each time android builds the project it seams to make sure the two files match, and replaces any inconsistencies between the two files.
Therefore, to change the color in the .xml resource file, you need to change the color in the original file. This can be done by editing it with another application. Or more simply, you can open the .svg file in a text editor and change it that way.
Here is an example .svg file downloaded from font awesome. To use it as a vector asset in android, just change fill="currentColor"
to any valid hexadecimal color string, e.g. fill="#000000"
.
<svg aria-hidden="true"
focusable="false"
data-prefix="fab"
data-icon="font-awesome-flag"
class="svg-inline--fa fa-font-awesome-flag fa-w-14"
role="img" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 448 512">
<path fill="currentColor"
d="M444.373 359.424c0 7.168-6.144 10.24-13.312 13.312-28.672 12.288-59.392 23.552-92.16 23.552-46.08 0-67.584-28.672-122.88-28.672-39.936 0-81.92 14.336-115.712 29.696-2.048 1.024-4.096 1.024-6.144 2.048v77.824c0 21.405-16.122 34.816-33.792 34.816-19.456 0-34.816-15.36-34.816-34.816V102.4C12.245 92.16 3.029 75.776 3.029 57.344 3.029 25.6 28.629 0 60.373 0s57.344 25.6 57.344 57.344c0 18.432-8.192 34.816-22.528 45.056v31.744c4.124-1.374 58.768-28.672 114.688-28.672 65.27 0 97.676 27.648 126.976 27.648 38.912 0 81.92-27.648 92.16-27.648 8.192 0 15.36 6.144 15.36 13.312v240.64z">
</path>
</svg>
Edit: I did some additional testing, and after I changed the original .svg file, android didn't update the .xml resource file when building. Also, the value of the color in this file isn't important because you can change it in your layout file, or dynamically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With