mihon/app/src/main/java/eu/kanade/tachiyomi/util/ImageViewExtensions.kt

20 lines
540 B
Kotlin
Raw Normal View History

package eu.kanade.tachiyomi.util
import androidx.annotation.DrawableRes
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import android.widget.ImageView
/**
* Set a vector on a [ImageView].
*
* @param drawable id of drawable resource
*/
fun ImageView.setVectorCompat(@DrawableRes drawable: Int, tint: Int? = null) {
val vector = VectorDrawableCompat.create(resources, drawable, context.theme)
if (tint != null) {
2017-01-08 18:50:51 +01:00
vector?.mutate()
vector?.setTint(tint)
}
setImageDrawable(vector)
}