//private BackgroundColorSpan span = new (Color.RED);//文字背景色private ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);//字体颜色
if (null != bean) { // vh.mNameTv.setText(bean.getSgName()); vh.mDesTv.setText(bean.getSgDescribe()); vh.mPetNmaeTv.setText(bean.getSgPetName()); vh.mHeadImg.setImageResource(bean.getSgHeadBp()); String username = bean.getSgName(); int index = username.indexOf(result, 0); Log.e("logcat", "result=" + result + ";username=" + username + ";index=" + index); if (index < 0) { vh.mNameTv.setText(username); } else {//设置username中,包含的result这些字的颜色为红色 SpannableString spanString = new SpannableString(username); spanString.setSpan(span, index, index + result.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); vh.mNameTv.setText(spanString); } }
安卓设置某些文字的字体颜色
最新推荐文章于 2023-06-24 17:14:40 发布