First of all, we need to know one thing that
Second, Happy to advertise that They re-enabled that VectorDrawable in Android Support Library 23.4.0
For AppCompat users, we’ve added an opt-in API to re-enable support Vector Drawables from resources (the behavior found in 23.2) via AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) — keep in mind that this still can cause issues with memory usage and problems updating Configuration instances, hence why it is disabled by default. If you want re-enable this, just stick this at the top of your Activity:
Finally, what thing we need to do
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Still need
I’m guessing that most of you will be using Gradle so let’s quickly walk through that. If you’re using v2.0 or above of the Gradle plugin, we have a handy shortcut to enable everything:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
If you have not updated yet, and are using v1.5.0 or below of the Gradle plugin, you need to add the following to your app’s build.gradle:
android {
defaultConfig {
// Stops the Gradle plugin’s automatic rasterization of vectors
generatedDensities = []
}// Flag to tell aapt to keep the attribute ids around
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
If you want to do something in your code
Drawable drawable = AppCompatResources.getDrawable(getContext(), R.drawable.your_vector_drawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null);
}
Thanks for reading, please feel free to comment with this post.