Add color filter over IconCompat

368 views Asked by At

I'm using a custom closed-source (not very well documented) library to create some Android Slices. For this I have to use IconCompat in order to load some icons in the slice. I would like to change the colours of these icons dynamically based on some backend data.

Tried doing it like so but the icon is still white regardless:

   val icon = IconCompat.createWithResource(context, R.drawable.calendar_slice_color)
   icon.setTintMode(PorterDuff.Mode.DST_ATOP)
   icon.setTint(event.color)

Any idea how to apply the color.event over the IconCompat before sending it to the slice?

1

There are 1 answers

2
Damir Colo On

Try this

icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);