Monday, January 9, 2017

How to use SVG images in Android Studio

Support Library

This technique requires Android Support Library 23.2 or higher and Android Plugin for Gradle 2.0 or higher, and uses vector drawables only. TheVectorDrawableCompat class in the Support Library allows you to support VectorDrawable in Android 2.1 (API level 7) and higher.
Before using Vector Asset Studio, you must add a statement to your build.gradle file:
android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}

dependencies {
  compile 'com.android.support:appcompat-v7:23.2.0'
}
You must also use coding techniques that are compatible with the Support Library, such as using the app:srcCompat attribute instead of theandroid:src attribute for vector drawables. For more information, see Android Support Library 23.2.

Running Vector Asset Studio


To start Vector Asset Studio:
  1. In Android Studio, open an Android app project.
  2. In the Project window, select the Android view.
  3. Right-click the res folder and select New > Vector Asset.
  4. Some other project views and folders have this menu item as well.
    Vector Asset Studio appears.
    Figure 1. Vector Asset Studio.
  5. If a Need Newer Android Plugin for Gradle dialog appears instead, correct your Gradle version as follows:
    1. Select File > Project Structure.
    2. In the Project Structure dialog, select Project.
    3. In the Android Plugin Version field, change the Android Plugin for Gradle version to 1.5.0 or higher, and click OK.
    4. Gradle syncs the project.
    5. In the Android view of the Project window, right-click the res folder and select New > Vector Asset.
    6. Vector Asset Studio appears.
  6. Continue with Importing a Vector Graphic.

0 comments:

Post a Comment