This is my build.gradle
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
vectorDrawables.useSupportLibrary = true
}
and a part of the layout
<ImageView
android:id="@+id/recents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:scaleType="fitCenter"
app:srcCompat="@drawable/anim_test"/>
and the class cast:
val np = convertView.findViewById<ImageView>(R.id.recents)
val anim = np.drawable as AnimatedVectorDrawableCompat
This works as expected on Lolipop (sdk 21) but fails on Nougat saying:
android.graphics.drawable.AnimatedVectorDrawable cannot be cast to android.support.graphics.drawable.AnimatedVectorDrawableCompat
What I dont get is, why does it return an AnimatedVectorDrawableCompat on sdk level 21 at all when AnimatedVectorDrawable is already supported by the system. And why does it return the AnimatedVectorDrawable in Nougat in spite of specifying vectorDrawables.useSupportLibrary = true.