Search code examples
androidandroid-layoutkotlinvectorandroid-vectordrawable

Change tint color in Kotlin


I want to change color of vector image at runtime.

XML example (ImageView):

app:tint="@android:color/holo_green_light"

How do I change this in Kotlin?


Solution

  • Use setColorFilter

    imageView.setColorFilter(ContextCompat.getColor(this, R.color.blue), android.graphics.PorterDuff.Mode.SRC_IN)