2016-03-13 22:06:32 +01:00
|
|
|
package eu.kanade.tachiyomi.util
|
|
|
|
|
2020-01-05 17:29:27 +01:00
|
|
|
import androidx.annotation.DrawableRes
|
|
|
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
2016-03-13 22:06:32 +01:00
|
|
|
import android.widget.ImageView
|
|
|
|
|
|
|
|
/**
|
2016-04-08 16:18:41 +02:00
|
|
|
* Set a vector on a [ImageView].
|
2016-03-13 22:06:32 +01:00
|
|
|
*
|
|
|
|
* @param drawable id of drawable resource
|
|
|
|
*/
|
2016-04-08 16:18:41 +02:00
|
|
|
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()
|
2016-04-08 16:18:41 +02:00
|
|
|
vector?.setTint(tint)
|
2016-03-13 22:06:32 +01:00
|
|
|
}
|
2016-04-08 16:18:41 +02:00
|
|
|
setImageDrawable(vector)
|
2020-01-05 17:29:27 +01:00
|
|
|
}
|