Difference between app:srcCompat and android:src in Android's layout XML
app:srcCompat
is the most foolproof method of integrating vector drawables into your app.Vector drawables allow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices
Note
As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat
.
you need to add vectorDrawables.useSupportLibrary = true to your build.gradle
file
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
android:src
Sets a drawable as the content of this ImageView.It will display in its original size. No automatic scaling .
If you are using android:src="@drawable/some_vector"
without vectorDrawables.useSupportLibrary = true
in build.gradle file and your app have vector images (vector drawable), then while building the apk file Android gradle plugin generates a lot of *.png files for different screens (hdpi, xhdpi...) from each of your vector drawable (only for API =< 19). The result - bigger size of apk.
When using app:srcCompat="@drawable/some_vector"
with vectorDrawables.useSupportLibrary = true
android uses vector drawable files without generating *.png
files.
You can check this with Android Studio apk analyzer tool. Just build apk with and without vectorDrawables.useSupportLibrary = true
.
I think this is the main difference.