Prathamesh More 2022-01-22 10:37:23 +05:30
parent 7226f9e76c
commit 1dc310d657

View file

@ -1,8 +1,10 @@
package code.name.monkey.appthemehelper.util
import android.content.Context
import android.graphics.Color
import androidx.annotation.AttrRes
import androidx.core.content.res.use
import java.lang.Exception
/**
* @author Aidan Follestad (afollestad)
@ -16,7 +18,11 @@ object ATHUtil {
@JvmOverloads
fun resolveColor(context: Context, @AttrRes attr: Int, fallback: Int = 0): Int {
context.theme.obtainStyledAttributes(intArrayOf(attr)).use {
return it.getColor(0, fallback)
return try {
it.getColor(0, fallback);
} catch (e: Exception) {
Color.BLACK
}
}
}
}