Drawable color got pale when accessed in RecyclerView but normal if not inside RecyclerView

47 Views Asked by At

I want to show drawable vector asset (.xml format) inside RecyclerView and give it a tint. But it doesnt show up nicely and kind of pale/faded out. I try to hardcode the tint color value and got the same result.

Here is the code

<!-- This doesnt work: using RecyclerView -->
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/rv_services"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="0dp"
    android:layout_marginTop="16dp"
    android:alpha="1"
    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/gopay"
    app:spanCount="4"
    tools:itemCount="8"
    tools:listitem="@layout/item_main_service" />

<!-- This works: accessing item layout directly -->
<include
    layout="@layout/item_main_service"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/rv_services" />

Here is the item layout file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_columnWeight="1"
    android:orientation="vertical"
    tools:ignore="UseCompoundDrawables">

    <ImageView
        android:id="@+id/iv_service"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:src="@drawable/ic_round_sports_motorsports_24"
        app:tint="@color/green_500" />

    <TextView
        android:id="@+id/tv_service"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/TextAppearance.MaterialComponents.Caption"
        android:textColor="@color/black"
        tools:text="GoRide" />

</LinearLayout>

And here is the screenshot

enter image description here

If i use jpg/png it works though

enter image description here

The drawable used is Material Icons that comes with Android Studio. How can this happens and how to solve it?

1

There are 1 best solutions below

0
wiryadev On

Solved, i was using Coil to load the drawable. Replacing with Glide or even manual setImageResource works.