How to change color of drawable ImageView android kotlin

104 Views Asked by At

i have a vector icon in my drawable package ic_vector_point_image:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="10dp"
    android:height="10dp"
    android:viewportWidth="3"
    android:viewportHeight="3">
  <path
      android:pathData="M1.5,1.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"
      android:fillColor="#4C55E4"/> --- blue color
</vector>

Then i use this vector icon with my ImageView:

<ImageView
        android:id="@+id/point"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3.7dp"
        android:src="@drawable/ic_vector_typing_indicator_point"
        app:layout_constraintBottom_toBottomOf="@id/typing_text"
        app:layout_constraintStart_toStartOf="parent"
        tools:ignore="ContentDescription" />

I need to set the argb color for this drawable like this: imageView.setColor(Color.argb()). How can i do this?

2

There are 2 best solutions below

0
César Bermúdez On

You can change the tint of the image view like this:

imageView.setColorFilter(Color.argb(255, 255, 255, 255)); // White

0
Dev4Life On

You can use setImageTintList() method for that.

In Kotlin:

imageView.imageTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.red))