Can you and should you use vector drawables? — A cheatsheet

David Ferrand
2 min readJan 25, 2017

--

All hail vector drawables!

Vector drawables allow you to support all screen densities with only one file. Two main advantages:

  1. The workflow of adding resources is simplified to a maximum: just drop your vectorial resource into res/drawable/. No need to create PNGs manually for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, etc.
  2. Having one file only — and lighter than a bitmap — allows you to save a few bytes (or KB, or MB) on your APK size.

Can I use them in my app?

Vector drawables have been introduced in Lollipop (API 21) and work 100% from Lollipop onwards. But things start to get tricky when you try to use vector drawables on older versions.

The Support Library brings some sort of backward-compatible support for vector drawables, but it doesn’t come without its compromises and big warning signs. Support was first introduced in version 23.2.0 of the Support Library, then partly removed in 23.3.0. In version 23.4.0 and until today (version 25.1.0), that part is back, but relegated behind an optional flag.

It’s important to mention version numbers because the proper way of doing things depends on which version you have, and some confusion exists in StackOverflow threads (e.g. here) depending on the date answers were written.

Decide whether vector drawables are for you

I am proposing the following diagram to help developers decide whether or not they can (or should) use vector drawables and at which cost. It is valid for Support Library versions 23.4.0 to (at least) 25.1.0.

It comes as a complement of Chris Banes’s very good tutorial AppCompat — Age of the vectors.

Edit May 2019: Things change quickly on Android. Much of this blog post is still valid, but one notable change since it was written is the introduction of AndroidX. It can be helpful to read Nick Butcher’s more recent and comprehensive article: Using vector assets in Android apps.

--

--