Pixelcat-App-Android/app/src/main/kotlin/at/connyduck/pixelcat/components/util/ThemeUtils.kt

15 lines
415 B
Kotlin
Raw Normal View History

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()
if(theme.resolveAttribute(attr, value, true)) {
return value.data
}
throw IllegalStateException("Attribute not found")
}