What SVG to XML Means
Every SVG is already an XML document, so the answer to svg to xml depends on what you need. Most developers searching for it want an Android vector drawable, the XML format that Android uses for scalable icons. Others only want their SVG written as tidy XML with a declaration, which some tools and parsers expect. This converter does both with one switch.
- Android vector drawable: a <vector> file that goes into res/drawable and works with ImageView, Jetpack Compose and Material components.
- Formatted XML: the same SVG, re-indented and starting with <?xml version="1.0" encoding="utf-8"?>.
How SVG Maps to an Android Vector Drawable
A vector drawable has a smaller vocabulary than SVG, so the tool translates each SVG feature into the closest Android one:
- Size: the SVG width and height become android:width and android:height in dp, and the viewBox becomes viewportWidth and viewportHeight.
- Shapes: rect, circle, ellipse, line, polyline and polygon are rewritten as path data, since Android only draws paths.
- Colours: fill and stroke become fillColor and strokeColor. Named colours, short hex codes and rgb() values are converted. Opacity becomes fillAlpha and strokeAlpha.
- Stroke and fill details: width, line cap, line join, miter limit and the even-odd fill rule are carried over.
- Transforms: translate, scale, rotate and scale-and-translate matrices become nested <group> elements. Skew is not supported on Android.
Using the Result in Android Studio
- Save the output as a file such as ic_logo.xml and put it in app/src/main/res/drawable.
- Reference it with @drawable/ic_logo in a layout, or painterResource(R.drawable.ic_logo) in Jetpack Compose.
- To recolour an icon from code or a theme, remove the fillColor from the path and use a tint.
Need the opposite direction, for example to preview a drawable from a project or send it to a designer? XML to SVG converts a vector drawable back to a standard SVG. To turn an SVG into a PNG for app store listings, use SVG to PNG, and to turn a logo picture into an SVG first, try PNG to SVG.
Formatted XML for Other Uses
With the Android option off, the tool parses your SVG, checks that it is well-formed and writes it back with two-space indentation and an XML declaration. This helps when a build step, a legacy importer or a code review needs readable XML. The content of the SVG is not changed. Text inside elements such as <text> and <style> is kept exactly as written.