Skip to content

Path fill rule support

a-student edited this page May 21, 2019 · 6 revisions

VectorDrawable path fill-rule is always non-zero and cannot be changed prior to Android 7.0 (Nougat, API level 24). If you end up with areas filled that should not be filled, that is because the SVG image was created using even-odd rule instead. There are three ways to deal with this problem: try specifying the Fix fill type option, manually edit SVGs in vector graphics software or convert for Android 7.0+.

Specifying the Fix fill type option

This option is experimental, but it is worth trying first (if fails, please open an issue). The option uses advanced mathematics to rebuild paths in such a way that rendering with any fill rule leads to the same result.

The converter suggests specifying the option if necessary. Slows down conversion when enabled.

Manual editing

If you are using Inkscape, open ObjectFill and Stroke… and in the Fill tab choose Fill is solid unless a subpath is counterdirectional. If you see an improperly filled area after this operation, using F2 tool select subpath around that area and apply PathReverse command from the main menu.

If you are using Sketch, select the path, right to the Fills property title there is a settings icon, click it and choose Non-Zero option. To reverse the path direction apply LayerPathsReverse Order command from the main menu.

Converting for Android 7.0+

By default, for older devices, Android Studio generates PNG images at build time. Alternatively, you can try AndroidX VectorDrawableCompat.

It won't help if a clipping path uses the even-odd fill-rule.