2016-03-13 17:06:32 -04:00
|
|
|
package eu.kanade.tachiyomi.util
|
|
|
|
|
|
|
|
import android.support.annotation.DrawableRes
|
|
|
|
import android.support.v4.content.ContextCompat
|
2016-03-12 08:22:40 -05:00
|
|
|
import android.support.v4.graphics.drawable.DrawableCompat
|
2016-03-13 17:06:32 -04:00
|
|
|
import android.widget.ImageView
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a drawable on a [ImageView] using [ContextCompat] for backwards compatibility.
|
|
|
|
*
|
|
|
|
* @param drawable id of drawable resource
|
|
|
|
*/
|
|
|
|
fun ImageView.setDrawableCompat(@DrawableRes drawable: Int?) {
|
|
|
|
if (drawable != null) {
|
2016-03-12 08:22:40 -05:00
|
|
|
var drawable = ContextCompat.getDrawable(context, drawable)
|
|
|
|
DrawableCompat.setTint(drawable,this.context.theme.getResourceColor(android.R.attr.textColorHint))
|
|
|
|
setImageDrawable(drawable)
|
2016-03-13 17:06:32 -04:00
|
|
|
} else {
|
|
|
|
setImageResource(android.R.color.transparent)
|
|
|
|
}
|
|
|
|
}
|