19

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?

Taig
  • 6,718
  • 4
  • 44
  • 65
  • xml to png? why? i cant see any reason... – pskink Jun 13 '15 at 06:27
  • @pskink I guess a reason is that VectorDrawable is only supported on API 21+ (Although, VectorDrawableCompat maybe coming soon to the support library) – BrentM Jun 13 '15 at 07:04
  • "To save time, hassle and decrease apk size" http://www.youtube.com/watch?v=f7ihSQ44WO0&t=2m40s – Taig Jun 13 '15 at 07:24
  • no, my question is not why you want to use VectorDrawables, but why to convert them to pngs... – pskink Jun 13 '15 at 07:26
  • Because it will work absolutely flawlessly on older API devices and relieves me of the burden of handling 6 image files by myself. – Taig Jun 13 '15 at 07:33
  • if you have any `Drawable` just use it where `Drawable` can be used (`View#setBackground`, `ImageView#setImageDrawable`, etc) you really **don't** need to convert it to png – pskink Jun 13 '15 at 07:43
  • But then I have to use 3rd party libs to convert the vector to a drawable first and I can not use the convenient resourse id (e.g. setDrawable(R.id.x)) which sometimes is the only way. – Taig Jun 13 '15 at 07:51
  • VectorDrawables were added in API level 21, for older devices you need to use MrVector or similar back-ports – pskink Jun 13 '15 at 08:03
  • On io15, Google announce support to gradle convert vector image files to png assets on **build** time for older version apks (instead use vector drawables or some sort of runtime backport). On API level 21, there is no need to conversion and drawable dirs can stay unchanged. – Renascienza Jun 14 '15 at 02:24
  • Looks like gradle build tools 1.4.0-beta has support of the build time PNG generation – ls.illarionov Aug 29 '15 at 03:32
  • Yup, as shown at DroidconNYC https://plus.google.com/+RomanNurik/posts/VHc6qLsMrXP or do you have any better reference? – Taig Aug 29 '15 at 08:43
  • 1
    @Taig, http://tools.android.com/tech-docs/new-build-system I just placed an `.xml` vector image file into `res/drawable/` directory and found it automatically converted in the build `.apk`. Unfortunately, this feature is not yet documented. – ls.illarionov Sep 01 '15 at 10:35
  • please check http://stackoverflow.com/a/35738726/2826147 – Amit Vaghela Mar 02 '16 at 05:21

2 Answers2

17

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

Sandro Machado
  • 9,921
  • 4
  • 36
  • 57
8

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.

BrentM
  • 5,671
  • 3
  • 31
  • 38
  • Thanks for pointing me to the icons, that looks quite good already. And for the conversion, I probably just have to wait a few more weeks, I guess. – Taig Jun 13 '15 at 12:11