How to use VectorDrawable Android Example

Vector drawable’s saves size of the application. Android uses single version of the SVG (Scalable Vector Graphics) XML image and makes it adjustable to all the resolutions of phone.

The advantages of Vector drawable’s are,

  1. No need to maintain different resolution of images in multiple resolution folders like LDPI, MDPI, HDPI & XHDPI.
  2. keep single svg xml format image in Drawable folder & start using it.

Apple vector drawable image

Android app-compat support Library 23.2.0 supports vectordrawable from API 7 onwards. Here are the steps to use it in Application.

  1. Convert PNG, JPEG, GIF etc… multiple image format to SVG. Just use image converter tool.
  2. Convert SVG image to Android vectordrawable, use svg2android tool & generate XML.
  3. Copy the generated XML file and put it in drawable folder of application.
    vector XML in drawable folder
  4. Start using it in application.
    android:src="@drawable/apple"/> <!-- Vector drawable -->

Gradle file changes:
In order to get better support of SVG from API 7, its good to upgrade Android studio 2.0. The gradle V2.0 is also available by default.

In App Gradle file, update support lib dependency as

Run application in different resolutions of phones or emulator.