1

I am using Facebook's Fresco Android library (version 1.11.0).

I have a SimpleDraweeView with a failureImage drawable attribute. However, I'd like to set the tint color of this drawable.

I didn't find a "failureImageTint" or related. How would I do that?

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/image_cover"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_marginEnd="6dp"
    fresco:failureImage="@drawable/ic_error_img"
    fresco:failureImageScaleType="fitCenter"
    fresco:roundAsCircle="true" />
Luiz
  • 2,429
  • 8
  • 28
  • 43

1 Answers1

1

According to the code in the Fresco showcase app on Github, You might find it easier to do what you're looking for using code (they use a SimpleDraweeView inside a DraweeHierarchyFragment) - since all the advanced xml attributes for SimpleDraweeView do not list anything about tinting.

Here's what it would look like:

SimpleDraweeView draweeView = view.findViewById(R.id.image_cover);

Drawable failureDrawable = getResources().getDrawable(R.drawable.ic_error_black_96dp);
DrawableCompat.setTint(failureDrawable, Color.RED);

draweeView.getHierarchy().setFailureImage(failureDrawable, ScaleType.FIT_CENTER);

So, you pick a drawable image for your failure image, add a tint color to that drawable image and then add the tinted drawable image to your SimpleDraweeView using setFailureImage(...).

chornge
  • 2,021
  • 3
  • 28
  • 37