I have the following directory structure:
drawable/ic_logo.xml
drawable-v24/ic_logo.xml
The issue I am experiencing is that the v24
version of ic_logo
is not overriding the "default" drawable folder version and the application displays the default on all API versions.
The reason I have to use a v24
version is because of the vector containing a gradient which needs startX
, startY
etc. which are not available until API 24.
My minSdkVersion
is 21, and I'm calling the vector from a AppCompatImageView
like so:
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintRight_toRightOf="parent"
android:adjustViewBounds="true"
android:src="@drawable/ic_logo"
app:srcCompat="@drawable/ic_logo"
app:layout_constraintTop_toTopOf="parent"/>
Strangely, the logo is displayed correctly for API < 23 and API 24 and above when using the Android Studio previewer, but not on any emulator or live device.
Thanks to @PankajKantPatel, I have implemented a "workaround" for this.
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.M){
logo.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_logo, null));
}else{
logo.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_logo_24, null));
}
I still feel this is a bug as it should follow the same logic as an image asset, I will log a bug with Google for this.