在 Google IO,工具团队简要展示了定义具有特定后缀(例如 ic_heart_48px.xml)的矢量可绘制对象的可能性,然后将其转换为所有必要密度的 png。不幸的是,除了 IO 记录之外,我没有找到有关此功能的任何文档。
这是构建工具或 Android Studio 的功能吗?假设它是构建工具的一部分,它已经可用了吗?我应该使用哪个版本?我必须明确启用该功能吗?
Google 是否提供 Android xml 矢量格式的素材图标?
最佳答案
使用 Android Studio 1.4 和 Gradle Android 插件到 1.4.0-beta3(或更高版本),只需右键单击项目中的 res/drawable 文件夹并从内容菜单中选择 New → Vector Asset。
可以在 1.4 版的发行说明中看到,该工具还提供向后兼容性。
We are also excited to offer backwards compatibility for your vector assets in Android Studio 1.4. Once you have a vectorDrawable image in your res/drawable, the Gradle plugin will automatically generate raster PNG images for API level 20 and below during build time. This means you only need to update and maintain your vector asset for your app project and Android Studio can take care of image conversion process. Note, it is still best practice to create density dependent launcher icons in your res/mipmap folder.
请注意,尚不完全支持 svg 格式。可能缺少某些功能。
阅读有关此功能的完整博客文章并在此处观看视频:http://android-developers.blogspot.pt/2015/09/android-studio-14.html
关于android - 自动转换为 png 的矢量可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30813667/