I have a problem with rendering vector drawable on Motorola pre-lollipop phones. I tested it on Moto G and other with KitKat. Every time I start application some icons look corrupted and some are missing at all. And after each launch they are corrupted in a different way. On Lenovo, Samsung, AOSP Emulator and others with JB+ till Nougat everything is ok. Only Motorola phones can not render vector drawables with support library well. Does anybody have the same issue?
Android - support vector drawables on Motorola
253 Views Asked by Mykhailo Yuzheka AtThere are 5 best solutions below
On
If you want to use vector with ImageView, you should use srcCompat-AppCompatImageView. However, if you want to use vector with drawableLeft.. use this library https://github.com/bsobe/vectorview
On
Try adding the following to onCreate() method of your Application class:
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
From official docs:
When enabled, AppCompat can intercept some drawable inflation from the framework, which enables implicit inflation of vector drawables within DrawableContainer resources.
You can then use those drawables in places such as android:src on ImageView, or android:drawableLeft on TextView.
This feature defaults to disabled, since enabling it can cause issues with memory usage, and problems updating Configuration instances.
If you update the configuration manually, then you probably do not want to enable this. You have been warned.
On
In my Research I found two ways to support vector drawable on pre lollipop devices. You can try this.
You can support all devices with vector drawable with AppCompatImageView
<android.support.v7.widget.AppCompatImageView
app:srcCompat="" // your drawable declaration
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android.support.v7.appcompat:srcCompat
Sets a drawable as the content of this ImageView. Allows the use of vector drawable when running on older versions of the platform.
Requires Support Library 23.4.0 or latest
Another way is to configure vector drawable setting in Gradle. Include the below code in your Gradle.
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
The use srcCompat in your ImageView
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_add" />
Source: https://android-developers.googleblog.com/2016/02/android-support-library-232.html
Hope it helps you :)
Vector Drawables are also supported in cases like TextView's drawableLeft property. go this link Android Studio 1.4