一个textView中的文字设置成两种颜色

使用Spannablestring和ForegroundColorSpan。

SpannableString string2 = new SpannableString("自助导入会员和连续开单
3个月可获得免费短信服务");
        ForegroundColorSpan span2 = new ForegroundColorSpan(getResources().getColor(R.color.worker_main_worker));
        string2.setSpan(span2, 12, 15, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  //12-15个字符颜色为span2中设置的值
        contentTv2.setText(string2);
        ikonwBtn.setText("我知道了");
原文地址:https://www.cnblogs.com/ivan-aldrich/p/4911553.html