Issue
I have an icon which look like this:icon in my constraint layout.
This is my layout xml for this image view:
<ImageView
android:id="@+id/vTotalPaidAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:contentDescription="@null"
android:src="@drawable/ic_group_ic_total"
tools:src="@drawable/ic_group_ic_total"
app:layout_constraintLeft_toLeftOf="@+id/vSettleDebtsLayout"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
app:layout_constraintTop_toTopOf="@+id/vSettleDebtsLayout"
android:layout_marginTop="16dp"
android:background="@drawable/avatar_circle" />
As you can see, the icon is just a dollar sign. I set that grey circle as background. The problem is that I need to change color of that background dynamically. The dollar sign need to stay white. My question is, is there any way how to change only the color of background?
Another solution would be to use that circle as next imageview and then change color of that image view. But i think that there could be some more "clear solution for this issue.
Thanks for tips :)
Solution
Try:
yourImage.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
This literally gets background (without src) from ImageView and covers its shape with color. The way the drawable and given color are combining is defined by mode of Porter Duff - here you have more about it.
Answered By - paulina_glab
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.