自动转换为 png 的矢量绘图

Vector drawables that are automatically converted to pngs

在 Google IO 上,工具团队简要展示了使用特定后缀定义矢量绘图的可能性(例如 ic_heart_48px.xml) 然后将转换为所有必要密度的 png。不幸的是,除了 IO 记录之外,我没有找到任何关于此功能的文档。

这是构建工具或 Android Studio 的功能吗?假设它是构建工具的一部分,它已经可用了吗?我应该使用哪个版本?我必须明确启用该功能吗?

Google 是否以 Android xml 矢量格式提供其 material 图标?

Google 开始以 VectorDrawable xml 格式提供 material 设计图标。

git 存储库位于此处:

https://github.com/google/material-design-icons

在 Google I/O Material 开始时,VectorDrawable xml 格式的设计图标被添加到存储库中(连同记录在案的其他更新 here). They are located in folders named drawable-anydpi-v21. For example, here are the communication icons in xml .

以下是 Google 关于添加这些新的 Vector Drawables 的评论:

Add a first cut at some Vector Drawables for these icons.

Only black, 24dp vector drawables are included.

We fully expect these icons to work correctly, how they should be considered 'beta' until we've more fully fleshed out the best practices for using them.

更新:post announcing Android Studio 1.3 being promoted to beta 指出由于各种错误,矢量光栅化支持仍未启用。

使用 Android Studio 1.4 和 Gradle Android 1.4.0-beta3(或更高版本)插件,只需右键单击 res/drawable 文件夹在您的项目中,然后从内容菜单中选择新建 → 矢量资源。

可以在 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 格式。可能缺少某些功能。

阅读有关此功能的完整博客 post 并在此处观看视频:http://android-developers.blogspot.pt/2015/09/android-studio-14.html