private voidcolorKeyWords(Stringtitle,StringkeyWord,TextViewtextView,intcolor){
SpannableStringstr=newSpannableString(title);
intstart=0;
start=title.indexOf(keyWord);
for(; ;){
start=title.indexOf(keyWord,start);
if(start>=title.length()){
break;
}
if(start<0){
break;
}
str.setSpan(newForegroundColorSpan(AppData.getContext().getResources().getColor(color)),start,start+keyWord.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
start+=keyWord.length();
}
textView.setText(str);
}











网友评论