Using Vector Assets for Icons in Android Studio 1.4

Since Android Studio 1.4, we can use Vector Assets which was earlier restricted to Lollipop alone. This is more efficient since one drawable which requires multiple instances saved in different density folders will now be replaced by just ONE single vector asset inside res/drawable/

You need to use Gradle 1.4 for this. 

icon icon
icon icon
  1. Add 'com.android.tools.build:gradle:1.5.0' to your build.gradle file dependencies.
  2. Add a vector asset by right-clicking res/drawable/ > New > Vector Asset. Android Studio provides a built-in viewer for you to pick your drawable.
  3. Reference your icon like you usually do. Eg: android:icon="@drawable/ic_help_24dp"

NOTE: 

Since the icons are black, you may want to tint your ActionBar icons white. You can do so by reference the icon like this: menu.getItem(index).getIcon() and then use DrawableCompat to tint.

Subscribe to stay updated
You'll be first to know about new articles and more. They're sent straight to your inbox!
No Spam, no BS. Promise. You can unsubscribe anytime.
App developer with an eye for design. Loves to create apps with good UI/ UX that doesn't annoy people. In his spare time, he likes to draw and paint.

Suleiman

App developer with an eye for design. Loves to create apps with good UI/ UX that doesn't annoy people. In his spare time, he likes to draw and paint.

You may also like...

  • Amr Aborig

    L is missing in gradle

    • Good eye! Thank you for noticing my mistake. Have fixed it now 🙂

  • 咕咚

    nice~

  • But tinting drawables using DrawableCompat in support-v4 have a bug as you can see in my issue reported here https://code.google.com/p/android/issues/detail?id=198082.

  • Binh Nguyen

    I think it is possible to change the color of an icon directly in its drawable file. Is there a reason that you used DrawableCompat to tint the icon instead?

    • Using the Vector Drawable assets, the imported icon is by default black. When I used these on a Toolbar menu, it wasn’t white.

      Hence why I had to tint it manually.

Subscribe to stay updated
You'll be first to know about new articles and more. They're sent straight to your inbox!
No Spam, no BS. Promise. You can unsubscribe anytime.
Gradle setup, ProGuard rules, Material Design palette, metrics and much more

FREE Material Design Starter Project

For more details, click on the below link.
GET IT NOW FOR ANDROID STUDIO!
Download FREE
STARTER PROJECT
Material Design Template Project for Android Studio
DOWNLOAD STARTER PROJECT
Android O is finally here!
Ready your Apps to get an advantage on Play Store.