Is it possible to check if the background color matches a given color with espresso?
Update:
I made a custom matcher, similar to what @Irfa
private fun hasBackgroundColor(colorRes: Int): Matcher {
Checks.checkNotNull(colorRes)
return object : TypeSafeMatcher() {
override fun describeTo(description: Description?) {
description?.appendText("background color: $colorRes")
}
override fun matchesSafely(item: View?): Boolean {
val context = item?.context
val textViewColor = (item?.background as ColorDrawable).color
val expectedColor: Int?
if (Build.VERSION.SDK_INT <= 22) {
expectedColor = context?.resources?.getColor(colorRes)
} else {
expectedColor = context?.getColor(colorRes)
}
return textViewColor == expectedColor
}
}
}