I am trying to color part of a string using spannableString and regular expressions in Android using this function:
public static String StringReplace(String source) {
String find = "ABC";
SpannableString replace = new SpannableString(find);
replace.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
String output = source.replace(find, replace);
return output;
}
Because the function replace() returns a string I am not able to get a colored string. My question is: what is the best way to color part of a text using regexp?
See Question&Answers more detail:os