https://kotlinlang.org logo
#compose
Title
# compose
c

chris

09/11/2020, 5:50 PM
How can I get a composable preview to correctly tint a vector/drawable in an
AndroidView
based on the theme that is wrapping it? I'm using an
AndroidView
so that I can use an
ImageView
because I'm being passed a
@DrawableRes
and I don't know if it will be a vector or a drawable.
z

Zach Klippenstein (he/him) [MOD]

09/11/2020, 6:04 PM
I think you’d have to get the tint out of the theme, and then manually pass the tint to the
ImageView
.
t

Timo Drick

09/11/2020, 11:24 PM
Why do you not know if it is a vector or bitmap? I had a problem that on old devices my vectors got converted to bitmaps but i was able to deactivate this behaviour by set vectorDrawables.useSupportLibrary = true
c

chris

09/23/2020, 3:36 PM
I don't know because I'm letting the user of the composable pass in an Int of a
@DrawableRes
t

Timo Drick

09/23/2020, 11:57 PM
Ok i see. Many of the new material composables let the user specify an composable instead of an icon or an drawable. I like it be cause you get much more freedom as api user. Maybe you should consider doing the same. But of course i do not know you specific use case. Maybe it is not applicable there.