Search code examples
androidandroid-imageviewlayout-xml

Difference between app:srcCompat and android:src in Android's layout XML


Whenever I create an ImageView with icon added using Android Studio's Vector Assets, I'm getting an error at the line app:srcCompat="@drawable/ic_play"

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

android:src="@drawable/ic_play"

Solution

  • 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 .