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);

 

posted on 2020-05-21 17:00  赵子隆  阅读(364)  评论(0编辑  收藏  举报

导航