一种:字体颜色改变
String appname= info.appname; //字符串内容
int start = appname.indexOf(mKeywordname); //mKeywordname需要改变颜色的字符串
ColorStateList redColors = ColorStateList.valueOf(0xFF960c0c);//0xFF960c0c颜色值
SpannableStringBuilder spanBuilder =new SpannableStringBuilder(appname);
spanBuilder.setSpan(new TextAppearanceSpan(null, 0, 0, redColors, null), start, start +mKeywordname.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
searchAppItem.mSearchAppListAppNameTextView.setText(spanBuilder);
二种:字体背景改变
SpannableStringBuilder style = new SpannableStringBuilder(appname);
style.setSpan(new BackgroundColorSpan(Color.RED), start, start +mKeywordname.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
searchAppItem.mSearchAppListAppNameTextView.setText(spanBuilder);