app直播源码,TextView部分字体颜色高亮
app直播源码,TextView部分字体颜色高亮实现的相关代码
/**
*Text box keyword highlight.
*
* @param color 高亮的颜色
* @param text 文本
* @param keyword 高亮的关键字
* @return SpannableString text是直接可以setText
*/
public static SpannableString getHighLightKeyWord(int color, String text, String keyword) {
SpannableString str = new SpannableString(text);
Pattern pattern = Pattern.compile(keyword);
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
str.setSpan(new ForegroundColorSpan(color), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return str;
}
以上就是 app直播源码,TextView部分字体颜色高亮实现的相关代码,更多内容欢迎关注之后的文章
浙公网安备 33010602011771号