Search code examples
androidandroid-drawableandroid-vectordrawable

How to set color code from colors.xml in a vector drawable?


I want to set the color code in vector drawable from colors.xml file of res folder.


Solution

  • You can simply use

    android:fillColor="@color/colorRated"
    

    But it may not work for some low android version device. Thats why usually i use direct xml color.

    android:fillColor="#9ec8e6"
    

    So, finally it looks like:

    <?xml version="1.0" encoding="utf-8"?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:width="48dp"
        android:height="48dp">
        <path
            android:pathData="M23.7 12A11.7 11.7 0 0 1 12 23.7 11.7 11.7 0 0 1 0.30000019 12 11.7 11.7 0 0 1 12 0.30000019 11.7 11.7 0 0 1 23.7 12Z"
            android:fillColor="#9ec8e6" />
    </vector>