I'm making a binding adapter where a I can set color filter to a drawable.
So I have these lines of code in java class
@BindingAdapter(value = {"drawable", "filterColor"}, requireAll= true)
public static void setColorFilterToDrawable(View view, int drawableInt, @ColorRes int color){
Drawable drawable = ContextCompat.getDrawable(view.getContext(),drawableInt);
drawable.setColorFilter(new
PorterDuffColorFilter(ContextCompat.getColor(view.getContext(), color), PorterDuff.Mode.SRC_IN));
view.setBackground(drawable);
}
In XML, I use it like this
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/textCircle"
android:drawable="@{@drawable/background_circle}"
app:colorFilter="@{@color/primaryDark}"
android:gravity="center"
android:layout_alignParentRight="true"
android:textColor="@android:color/white"
android:textSize="14sp"
android:text="X"
android:textStyle="bold"
android:layout_marginRight="5dp"
android:onClick="@{viewModel::deletePhoto}" />