svgtoandroid

Project Url: misakuo/svgtoandroid
Introduction: An Intellij platform plugin to transforming SVG to android VectorDrawable
More: Author   ReportBugs   OfficialWebsite   
Tags:

Android Arsenal

README: 中文 | English

DEPRECATED

Please using the Asset Studio instead. 20201103111801.jpg

简介

Intellij Platform 插件,通过其可以完成从 svg 文件到 Android VectorDrawable 的自动化转换。

特性

  • 图形化界面
  • 自动解析当前 Project,如果当前 Project 为 Android Project,则会列出所有 Module
  • 支持将 SVG 解析为多种 dpi 的 VectorDrawable
  • 支持 SVG 的 transform 属性
  • 支持批量转换指定目录内的所有 svg 文件

属性对应表

SVG Attribute VectorDrawable Attribute
id android:name
fill android:fillColor
fill-opacity android:fillAlpha
fill-rule android:fillType
stroke android:strokeColor
stroke-opacity android:strokeAlpha
stroke-width android:strokeWidth
stroke-linejoin android:strokeLineJoin
stroke-miterlimit android:strokeMiterLimit
stroke-linecap android:lineCap
transform android:{scaleX/Y \ translateX/Y \ pivotX/Y \ rotation}

使用

安装

本插件支持 Intellij IDEA 和 Android Studio,需要 JDK 版本 1.6+

通过本地 jar 文件安装

从此处 下载svg2android.zip 文件,在 IDE 中打开 Preferences -> Plugins -> Install plugin from disk... 选择 svg2android.zip ,添加后重启 IDE

通过插件仓库在线安装

在 IDE 中打开 Preferences -> Plugins -> Browse Repositories,搜索 SVG2VectorDrawable,安装插件并重启 IDE

界面

img1

用法

GUI 模式

settings

  • 点击···按钮,选择一个 SVG 源文件,或勾选batch,并点击···选择一个包含 svg 文件的目录
  • 在第一个下拉选框中选中要生成 xml 文件的 module,在第二个选框中选择生成的 VectorDrawable 的分辨率
  • 填入生成 xml 文件的文件名,默认为 vectordrawable + SVG 文件的名称
  • 点击Generate,插件会生成出 VectorDrawable 并在编辑器中打开(默认覆盖同名文件)

注意:在 module 中已存在的分辨率目录为黑色字体,未存在的目录为灰色字体,如果选中不存在的目录,则插件会自动生成该目录。

Generate 模式

settings

  • 在任意代码编辑器窗口中呼出Generate菜单(例如 macOS 默认是 control+enter)
  • 选择VectorDrawable,插件会将指定目录中的所有 svg 文件转换到当前 module 的 drawable 目录中(默认跳过同名文件)

设置项

打开Prefreences -> Other Settings,选择SVG to VectorDrawable,打开设置面板

settings

  • SVG source: 设置存放 svg 文件的默认目录,在 Generate 模式中将会从该目录获取 svg 文件
  • Xml prefix: 设置生成的 xml 文件名的默认前缀
  • Auto check for update: 勾选后在每次打开 GUI 的时候会进行自动版本更新检查操作
  • Override the existing xml file when generating: 勾选后在生成过程中将会覆盖已存在的同名文件

更新日志

1.5

支持 fill-rule 属性(该属性目前仅被 API 24+支持)
添加 Generate 模式
支持批量生成

1.4.2

针对 Sketch 导出的 SVG 文件做了优化

1.4.1

代码优化,更换新 Icon

1.4.0

支持“transform”属性

Early

创建项目,bug fix

欢迎提交 Issue 和 PR


Reference: svg2vectordrawable

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools