Use fillType="evenOdd" on Android 21

njzk2 picture njzk2 · Dec 16, 2016 · Viewed 12.1k times · Source

I have an SVG image that I want to include in an Android project.

The minSdk version for the project is 9. Android Studio is generating PNG files for the SVG.

However, for API 21+, Android studio includes the SVG in a drawable-anydpi-v21 resource folder.

That means that any device running API 21 and up will use the SVG instead of the PNGs.

And that is the problem: my SVG requires android:fillType="evenOdd".

The PNG are properly generated, but for the SVG, because that attribute is API 24+, it is ignored on API 21 devices, and the image appears filled instead of being a wireframe-like image.

Is there anyway to convince Android studio to only include the PNG and drop the SVG completely?

Is there an other solution for this?

Answer

Kirit Khant picture Kirit Khant · Jan 22, 2020

Attribute android:fillType is only used in API level 24 and higher. For below API level, follow these steps.

  1. add this to your Gradle file.

    //Gradle Plugin 2.0+
    android {
      defaultConfig {
         ...
         vectorDrawables.useSupportLibrary true
      }
    }
    
  2. If you are using ImageView, change its property android:src to app:srcCompat.

  3. If you are using as android:drawableStart or android:drawableEnd in TextView, change it to app:drawableStartCompat or app:drawableEndCompat.