This is my build.gradle
defaultConfig { ... minSdkVersion 21 targetSdkVersion 26 vectorDrawables.useSupportLibrary = true }
and 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 cast class:
val np = convertView.findViewById<ImageView>(R.id.recents) val anim = np.drawable as AnimatedVectorDrawableCompat
This works as expected on Lolipop (sdk 21), but Noug says with an error:
android.graphics.drawable.AnimatedVectorDrawable cannot be cast to android.support.graphics.drawable.AnimatedVectorDrawableCompat
What I do not get is why it returns AnimatedVectorDrawableCompat at SDk level 21 at all when AnimatedVectorDrawable is already supported by the system. And why does it return AnimatedVectorDrawable to Nougat, despite the indication of vectorDrawables.useSupportLibrary = true .
source share