SpannableString 设置文字中的颜色 链接
SpannableString spannableString = new SpannableString(matchResult); int index = matchResult.indexOf(mKeyword); if (index != -1) { spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(holder.itemView.getContext(), R.color.search_txt_green)), index, index + mKeyword.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } itemView.setText(spannableString);