Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there still any difference between android:src vs app:srcCompat?

Tags:

android

I read about app:srcCompat on stackoverflow and also from other resources that the main purpose of this attribute is to support for vector-drawable. But I got confused when android:src is also working fine with vector-drawable.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M10.18,9"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M21,16v-2l-8,-5V3.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S10,2.67 10,3.5V9l-8,5v2l8,-2.5V19l-2,1.5V22l3.5,-1 3.5,1v-1.5L13,19v-5.5l8,2.5z"/>
</vector>

I saved the above code in abc.xml file in drawable directory, then I use it with android:src

<ImageView
        android:id="@+id/imageView"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:src="@drawable/abc" />

It is working fine. Then where app:srcCompat is helpful or is there any difference between them? or I understand it wrong?

like image 542
Asif Mushtaq Avatar asked Sep 06 '25 03:09

Asif Mushtaq


1 Answers

Yes, there is a difference. There is an article here about it. Basically app:srcCompat will work on older APIs when loading up vector drawables. You’ll find directly referencing vector drawables outside of app:srcCompat will fail prior to Lollipop, you are probably running the android:src on Lollipop or higher.

like image 65
riggaroo Avatar answered Sep 07 '25 22:09

riggaroo