I have a question about using `imageResource`/`vec...
# compose
v
I have a question about using `imageResource`/`vectorResource` in older Android SDK versions. I have an icon
Copy code
Icon(vectorResource(R.drawable.ic_accessory_arrow))
where
ic_accessory_arrow
is a vector drawable. This code crashes on API 21 with
android.content.res.Resources$NotFoundException: File res/drawable-xxhdpi-v4/ic_accessory_arrow.png from xml type xml resource ID #0x7f0800e3
exception. So, what should I do for older SDKs? Write it like that?
Copy code
// Random number here: I don't even know which API versions implicitly convert vector drawables to png
if (Build.VERSION.SDK_INT > 23) { 
    Icon(vectorResource(…)) 
} else { 
    Icon(imageResource(…)) 
}
n
With the latest alpha release we have a
painterResource
API that will automatically load an
ImagePainter
or a
VectorPainter
👍 1
And should not require having to do a manual API level check. That is if a certain configuration has the resource identifier as a vector drawable it will be parsed as a VectorPainter but if it is a rasterized image (ex png/jpg) it will be loaded as a ImagePainter
v
That’s what I was waiting for! Thank you :)
👍 1