Vector drawables that are automatically converted to pngs

11.3k views Asked by At

At Google IO, the Tools team briefly showed the possibility to define vector drawables with a specific suffix (e.g. ic_heart_48px.xml) that will then be converted to pngs of all necessary densities. Unfortunately I don't find any documentation about this feature besides the IO recordings.

Is this a feature of the Build Tools or of Android Studio? Assuming it's part of the Build Tools, is it available already? Which version should I be using? Do I have to enable the feature explicitly?

Does Google provide its material icons in the Android xml vector format?

2

There are 2 answers

1
BrentM On BEST ANSWER

Google is starting to provide material design icons in the VectorDrawable xml format.

The git repository is hosted here:

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

At the start of Google I/O Material design icons in VectorDrawable xml format were added to the repository (along with other updates documented here). They are located in folders named drawable-anydpi-v21. For example, here are the communication icons in xml.

Here is what Google's comments say about the addition of these new 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.

Update: The post announcing Android Studio 1.3 being promoted to beta states that vector rasterization support is still not enabled due to various bugs.

0
Sandro Machado On

With Android Studio 1.4 and Gradle Android plugin to 1.4.0-beta3 (or higher) it is only necessary to right-clicking the res/drawable folder in your project and selecting New → Vector Asset from the content menu.

enter image description here

It is possible to read on the release notes of the version 1.4 that this tools also offers backwards compatibility.

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.

Note that the svg format is not fully supported yet. Some features may be missing.

Read the full blog post about this feature and see the video here: http://android-developers.blogspot.pt/2015/09/android-studio-14.html