String attention = getResources().getString(R.string.facebook_attention);//待修改字符串(例如关键字是5000)
String i=5000;
TextView tvAttention = (TextView) view.findViewById(R.id.tv_pay_attention);
SpannableStringBuilder ssbuilder = new SpannableStringBuilder(attention);
ForegroundColorSpan yellowSpan = new ForegroundColorSpan(getResources().getColor(R.color.yellow_fa));//修改关键字的字体颜色
ssbuilder.setSpan(yellowSpan, attention.indexOf(i), i.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tvAttention.setText(ssbuilder);
TextView 关键字颜色 样式修改
最新推荐文章于 2024-03-22 09:59:28 发布
本文介绍了一种在Android应用中实现关键词高亮显示的方法。通过使用SpannableStringBuilder结合ForegroundColorSpan,可以改变特定文本的颜色,从而达到高亮的效果。这种方法适用于需要在TextView中突出显示某些关键词的场景。
682

被折叠的 条评论
为什么被折叠?



