Created
September 30, 2013 19:22
-
-
Save mlc/6768769 to your computer and use it in GitHub Desktop.
workaround for android bug 58192
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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