Use style/theme colour on a vector asset

530 views Asked by At

Hi i am trying to set a fillcolour to use the theme/style of colorOnPrimary

via android:fillColor="?colorOnPrimary"

However i get this error: Invalid color value ?colorOnPrimary when i try and build my project

This is what my vector asset xml looks like:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="18dp"
    android:height="18dp"
    android:viewportWidth="18"
    android:viewportHeight="18">
    <path
        android:fillColor="?colorOnPrimary"
        android:fillType="evenOdd"
        android:pathData="...." />
</vector>
1

There are 1 answers

1
Rajan Kali On

For color use color-resources with @color, you might have colorPrimary in colors.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="18dp"
    android:height="18dp"
    android:viewportWidth="18"
    android:viewportHeight="18">
    <path
        android:fillColor="@color/colorOnPrimary"
        android:fillType="evenOdd"
        android:pathData="...." />
</vector>