This commit is contained in:
parent
7226f9e76c
commit
1dc310d657
1 changed files with 7 additions and 1 deletions
|
@ -1,8 +1,10 @@
|
||||||
package code.name.monkey.appthemehelper.util
|
package code.name.monkey.appthemehelper.util
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.core.content.res.use
|
import androidx.core.content.res.use
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Aidan Follestad (afollestad)
|
* @author Aidan Follestad (afollestad)
|
||||||
|
@ -16,7 +18,11 @@ object ATHUtil {
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun resolveColor(context: Context, @AttrRes attr: Int, fallback: Int = 0): Int {
|
fun resolveColor(context: Context, @AttrRes attr: Int, fallback: Int = 0): Int {
|
||||||
context.theme.obtainStyledAttributes(intArrayOf(attr)).use {
|
context.theme.obtainStyledAttributes(intArrayOf(attr)).use {
|
||||||
return it.getColor(0, fallback)
|
return try {
|
||||||
|
it.getColor(0, fallback);
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Color.BLACK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue