2020-06-12 15:44:45 +02:00
|
|
|
package at.connyduck.pixelcat.components.util
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.TypedValue
|
|
|
|
import androidx.annotation.AttrRes
|
|
|
|
import androidx.annotation.ColorInt
|
|
|
|
|
|
|
|
@ColorInt
|
|
|
|
fun Context.getColorForAttr(@AttrRes attr: Int): Int {
|
|
|
|
val value = TypedValue()
|
2020-06-12 19:58:15 +02:00
|
|
|
if (theme.resolveAttribute(attr, value, true)) {
|
2020-06-12 15:44:45 +02:00
|
|
|
return value.data
|
|
|
|
}
|
|
|
|
throw IllegalStateException("Attribute not found")
|
2020-06-12 19:58:15 +02:00
|
|
|
}
|