public static SpannableStringBuilder findSpecWordAndHighLight(String srcText, List keyWords, int highLightColor){
if (EmptyUtils.isEmpty(srcText))return new SpannableStringBuilder("");
SpannableStringBuilder spannable = new SpannableStringBuilder(srcText);
if (EmptyUtils.isNotEmpty(keyWords)) {
for (String sensitiveContentWord : keyWords) {
Pattern p = Pattern.compile(Pattern.quote(sensitiveContentWord));//关键字
Matcher m = p.matcher(srcText);//匹配关键字
while (m.find()) {
int start = m.start();
if (start >= 0) {
int end = start + sensitiveContentWord.length();
spannable.setSpan(new ForegroundColorSpan(highLightColor), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
}
}
}
}
return spannable;
}