A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information.
The major advantage of using a vector drawable is image scalability.
It can be scaled without loss of display quality, which means the same file is resized for different screen densities without loss of image quality.
This results in smaller APK files and less developer maintenance.
You can also use vector images for animation by using multiple XML files instead of multiple images for each display resolution.
You need to opt in to AndroidX vector support in your app’s build.gradle:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
This flag prevents the Android Gradle Plugin from generating PNG versions of your vector assets if your minSdkVersion is < 21—we don’t need this as we’ll use the AndroidX library instead.
- Don’t: android:src
- Do: app:srcCompat
- Don’t: android:button
- Do: app:buttonCompat
xmlns:app="http://schemas.android.com/apk/res-auto"