If I have a vector image in a program like Illustrator, how can I end up with the correct format for Android's VectorDrawable framework to use?
I found a tool to convert SVG to the VectorDrawable xml format: http://inloop.github.io/svg2android/ but it requires SVGs only use "path".
Any ideas how to output files like that?
PathData in vector images android is Vector graphic program's script. It is not exactly clean and human readable code as a high priority.
Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources.
A VectorDrawable XML file.
If you're using Android Studio, the best method is:
The wizard produces XML from your SVG files.
That tool only appears to currently support <path>
elements. So for example it doesn't support <rect>
, <circle>
etc.
If you are using primitives like this in your drawing, you need to convert them. I forget the exact option you need to use, but it's probably something like "Convert to path".
This link may help.
https://graphicdesign.stackexchange.com/questions/15475/convert-primitive-to-path-using-svg-format-in-illustrator
Just use SVG to VectorDrawable Converter or its online version. This is a batch converter of SVG images to Android VectorDrawable XML resource files.
Link points to readme, which provide enough information on how to use the converter.
Before saving your AI project file as an SVG
, make sure you:
Convert all paths to outlines, using Object > Expand...
.
Convert any shape paths (such as <circle>
) to Compound Paths
by right-clicking while you have the object/s selected, and choosing Make Compound Path
.
Once that's done each shape in the SVG should be a <path>
.
When I tried to convert an SVG of medium complexity to a vector drawable using the app mentioned in the question, I had issues with it forgetting some parts. I figured it must have something to do with the way it's formatted, so I decided to use SVGOMG, an SVG optimisation app, to strip it down to its bare essentials.
Use SVGOMG, or another app, to optimise the SVG, and then download the file.
Take the downloaded SVG and drop it into SVG2Android and it will give you what you're after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With