Skip to content

Instantly share code, notes, and snippets.

@mlc
Created September 30, 2013 19:22
Show Gist options
  • Save mlc/6768769 to your computer and use it in GitHub Desktop.
Save mlc/6768769 to your computer and use it in GitHub Desktop.
workaround for android bug 58192
/**
* Work around a bug in Android 4.3
*/
public static CharSequence fixFontColor(CharSequence seq, int color) {
if (Build.VERSION.SDK_INT < 18 || !(seq instanceof Spanned))
return seq;
Spannable txt = (seq instanceof Spannable ? (Spannable)seq : new SpannableString(seq));
for (ForegroundColorSpan ann : txt.getSpans(0, txt.length(), ForegroundColorSpan.class)) {
if (ann.getForegroundColor() != color) {
int start = txt.getSpanStart(ann), end = txt.getSpanEnd(ann), flags = txt.getSpanFlags(ann);
txt.removeSpan(ann);
txt.setSpan(new ForegroundColorSpan(color), start, end, flags);
}
}
return txt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment