Use fillType="evenOdd" on Android 21

android path filltype
android vector translate
android draw vector drawable on canvas
import android graphics drawable vectordrawable
android vector tint
android strokealpha

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?

Solution 1

Flattern image in Sketch and use this site to convert SVG to xml for Android

Solution 2

I use nonZero instead of evenOdd and open it in Sketch to reverse Order after reverse it will change pathData and remove android:fillType and everything work fine on Android 21+.

Solution 3



After some research I found that there are two fill-rule property methods for Vector graphics, SVGs, the "evenodd" vs "nonzero"

I opened the SVG icon in Sketch and inspected the hole at the top of the icon. As expected it uses fill-rule:evenodd property. Now I have to change the fill-rule to use "nonzero" property. How? Select the path. In the right side, there is a settings icon at the "Fills" property. Click it and choose "non-zero".

From the main menu, choose Layer → Paths → Reverse Order. I got the hole back at the top of the icon and got the hole in the app, too.

For more detail

Path.FillType, Android Studio warns me that it uses fillType="evenodd" which is only supported on API level 24 and higher. Most of our apps have a  The following are Jave code examples for showing how to use FillType of the class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.

SVGs with filltype="evenOdd" seems to work and display properly now with Android gradle plugin 3.2. You may also need to use Support Library 28 or AndroidX 1.0.

Make sure it's at least this version in your top level build.gradle:

classpath ''

Avoid fillType="evenOdd" in Android vector drawables. · Issue #28 , For example, using VectorDrawableCompat from AndroidX enables: Both nonZero and evenOdd path fillTypes —the two common ways of  type FillType = Public Enum FillType Inheritance. Object. ValueType. Enum. FillType. Fields. HorizontalGradient 2: The interior of the element is a horizontal gradient.

you can convert your svg to xml files, that will solve your problem, Here is the link for converting svg to xml files svgToXML

Using vector assets in Android apps - Android Developers, I read the VectorDrawable documentation again and then read a few articles about how to use it. Then I thought Android Studio would have messed up the icon  filltype. You can use the filltype property attribute of the <stroke> sub-element to draw an outline with various fill effects. Examples: If you specify <v:stroke filltype="solid" /> inside the <roundrect> element, you can create a rounded rectangle with the solid-filled outline, as shown in the following VML representation:

Convert your SVG file online, then remove android:fillType="evenOdd" in the generated xml file. Copy and paste the xml file in the res/drawable folder. Use it. Hope this helps!

The Mystery of the Disappearing Holes, The fill-rule attribute is a presentation attribute defining the algorithm to use to determine the inside part of a shape. Today we take a look at several "christmas" mods all released on Christmas Eve as gifts to us the players from the modding community. Lizard 2014 Pickup with the ability to add your own logo

fill-rule, If we render using the even-odd rule then we'll see the cutout; but if we that seems to be the perfect solution until we discover that the fillType  Filltype (Goods) Mass Adjustment (Realistic Weights) This mod makes sure that 10 Tons of wheat also weigh actual 10 tons, not only 5 tons. In the basegame all the masses of all the Filltypes (goods) are half of what they would be IRL.

VectorDrawable Fill Windings, function eventAssetsLoaded() { canvasApp(); } We are not going to use the pattern fillType describes how the text will be filled (a regular color fill, a linear  In Beta 1.3 the theme of the paths has been solved, you can use paths related to the folder of the mod I am having problems with the translation of the filltype name and additional fruits. If someone has resolved it, I would appreciate it if you can explain it.

HTML5 Canvas: Native Interactivity and Animation for the Web, Not all symbolizers are required, but you have to use at least one of them to including opacity, displacementX, displacementY, fill, fillBackground, fillType. Moin, bin dabei neue Früchte in meine Map einzubauen. Allerdings bekomme ich diese Warnings. Sonst läuft alles keine Errors oder andere Warnings in der Log. Wo kommen diese her? 2019-09-14 17:48 Enabled withering 2019-09-14 17:48 Warning: Unknown…

  • Have you tried moving your VectorDrawable to a folder named drawable-anydpi-v24?
  • There is not automated way to convert files that rely on evenOdd to nonZero because that is a visual difference, and a tool would have no idea what it is supposed to look like. Any conversion would have to be done manually in an editor.
  • @PaulLeBeau that's a good idea, although I fear that android studio would interprete that as not generating anything given that the asset is 24+ only. I'll try that to see what it does.
  • Any solution fr this one ?
  • Can you please show a sample SVG that requires evenOdd , and that without it, it will look different? I think it got fixed on later versions of
  • you don't have to use nonZero, that's the default value. Reversing it in sketch works, like other solutions that involve modifying the original SVG file, which is not what I am looking for as I'd rather be able to use the files sent by the designer directly.
  • After reversed in Sketch it will change pathData and remove android:fillType
  • Thanks. I am converting the SVG to XML, using Vector Asset Studio, which is included in Android Studio. This converter has the same problem: and it gave me an XML with android:fillType="evenOdd"
  • there are several other websites that convert svg to xml, did you tried some of them.
  • Did you upload your image or link in svg format, perhaps anyone can convert it.
  • I am looking for a more generic solution, as there will be more images of the same kind in the future
  • this one works a lot better for me. It does not support batch, but sometimes the result differed from the original SVG. Did not have it with this converter yet though, opposed to the one mentioned in the answer