iamatsundere181 iamatsundere181 - 1 year ago 114
Android Question

How to use vector drawables in Android API lower 21?

I am working on an Android project and I chose

to display icon because it is adaptable and dynamically, however, I just can run this app on devices run Android which have API 21 or more. My question is how can I use
on lower Android version i.e. API 14 or kind of. Thanks!

<!-- drawable/ic_android_debug_bridge.xmlxml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<path android:fillColor="@color/primaryColorDark"
android:pathData="M15,9A1,1 0 0,1 14,8A1,1 0 0,1 15,7A1,1 0 0,1 16,8A1,1 `0 0,1 15,9M9,9A1,1 0 0,1 8,8A1,1 0 0,1 9,7A1,1 0 0,1 10,8A1,1 0 0,1 9,9M16.12,4.37L18.22,2.27L17.4,1.44L15.09,3.75C14.16,3.28 13.11,3 12,3C10.88,3 9.84,3.28 8.91,3.75L6.6,1.44L5.78,2.27L7.88,4.37C6.14,5.64 5,7.68 5,10V11H19V10C19,7.68 17.86,5.64 16.12,4.37M5,16C5,19.86 8.13,23 12,23A7,7 0 0,0 19,16V12H5V16Z" /></vector>`

Answer Source

Vector Drawables are now backward compatible, it's just a matter of upgrading your gradle version to 1.4.0-beta3 or higher, and upgrade your IDE :

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.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download