TextView 关键字颜色 样式修改

来源:互联网 发布:王哲林体测数据曝光 编辑:程序博客网 时间:2024/06/06 03:48
    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);
原创粉丝点击