Vadim

    Vadim

    1 year ago
    I have a question about using imageResource/vectorResource in older Android SDK versions. I have an icon
    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?
    // 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(…)) 
    }
    Nader Jawad

    Nader Jawad

    1 year ago
    With the latest alpha release we have a
    painterResource
    API that will automatically load an
    ImagePainter
    or a
    VectorPainter
    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
    Vadim

    Vadim

    1 year ago
    That’s what I was waiting for! Thank you 😃