Zayid Mohammed Zayid Mohammed - 23 days ago 13
Android Question

Android: What is the difference between app:srcCompat=" " and android:src=" "?

Whenever i create an ImageView with icon added using Android Studio's Vector asset i'm getting error at the line

app:srcCompat="@drawable/ic_play"


And when i change the
app:srcCompat=""
with
android:src=""
the error is gone but the icon looks pixelated.

What is the main difference between

app:srcCompat="@drawable/ic_play"


and

adnroid:src="@drawable/ic_play"

Answer

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 .