Regular visitors of Styling Android knows of my passion for VectorDrawable and AnimatedVectorDrawable. While (during the time of writing) we’re still awaiting VectorDrawableCompat therefore we are only able to rely on them on API 21 (Lollipop) and then. However, the discharge of Android Studio 1.4 just added some backwards compatibility towards the build tools therefore we can really start using VectorDrawable for pre-Lollipop. In the following paragraphs we’ll check out the salt water evaporates.
Before we start let’s possess a quick recap of the items VectorDrawable is. Basically it’s an Android wrapper around SVG path data. SVG pathways are a good way of indicating complex graphical elements inside a declarative way. They’re particularly suitable for line sketches and vector graphics, and unacceptable for photo taking images. Typically in android developer we’ve ShapeDrawable where we are able to perform some fundamental stuff but frequently we must convert vector and line graphics directly into bitmaps at various pixel densities to use them.
Android Studio 1.4 introduces the opportunity to import SVG graphics into Android Studio and converts them instantly to VectorDrawable. These may be symbols in the material symbols pack or standalone SVG files. Importing material symbols works flawlessly and offers a sizable and wealthy group of symbols. However, importing standalone SVG files could be more problematic. The reason behind this would be that the VectorDrawable format only supports a subset of SVG and it is missing features for example gradient and pattern fills, local IRI references (the opportunity to give a component a distinctive reference and re-utilize it inside the SVG via that reference), and changes – all of which are generally used.
This really is basically just like the way the imported SVG was made before I by hand added the missing changes. I ought to point out that there’s a lint warning which signifies that elements aren’t supported for raster image generation, but that doesn’t diminish the truth that VectorDrawable is definitely an android developerspecific format so not fully supporting it appears baffling.
We currently starting to realise why changes aren’t based on the import tool – because changes on VectorDrawable elements isn’t supported when transforming VectorDrawable to some raster image for backwards compatibility. This could seem like major omission: Totally valid VectorDrawable assets which render perfectly under Lollipop and then don’t really render properly when transformed into PNG.
To, to summarise: If you are using these new tools to import assets in the material symbols library they work flawlessly. However, it appears misleading to even declare that the import tool is really able to importing SVG if this only supports a really limited subset, and won’t properly import most real-world SVG files. Furthermore the possible lack of support for the entire VectorDrawable specs within the VectorDrawable -> raster image conversion helps make the implementation feel incomplete and never really ready for general use.
For the amount of manual tweaking which i was needed to complete to even obtain the official SVG emblem to be also transformed into a VectorDrawable through the import tool it wouldn’t have needed a lot more try to by hand convert it to some VectorDrawable and completely bypass the import tool altogether. Although I’d be needed to by hand apply my changes to all the coordinates inside the SVG pathData elements to be able to by hand use the necessary changes.