Skip to content

Instantly share code, notes, and snippets.

@heitorcolangelo
Last active September 6, 2016 01:51
Show Gist options
  • Save heitorcolangelo/7f621a888c4ed5ec15529c6c05ddcdb3 to your computer and use it in GitHub Desktop.
Save heitorcolangelo/7f621a888c4ed5ec15529c6c05ddcdb3 to your computer and use it in GitHub Desktop.
To match textColor of a TextView
public class TextColorMatcher {
private TextColorMatcher(){}
public static Matcher<View> withTextColor(@ColorInt final int expectedColor) {
return new BoundedMatcher<View, TextView>(TextView.class) {
int currentColor = 0;
@Override
public void describeTo(Description description) {
description.appendText("expected TextColor: ")
.appendValue(Integer.toHexString(expectedColor));
description.appendText(" current TextColor: ")
.appendValue(Integer.toHexString(currentColor));
}
@Override
protected boolean matchesSafely(TextView item) {
if(currentColor == 0)
currentColor = item.getCurrentTextColor();
return currentColor == expectedColor;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment