TextView字体颜色

Spanned.SPAN_EXCLUSIVE_EXCLUSIVE(前后都不包括)、

Spanned.SPAN_INCLUSIVE_EXCLUSIVE(前面包括,后面不包括)、

Spanned.SPAN_EXCLUSIVE_INCLUSIVE(前面不包括,后面包括)、

Spanned.SPAN_INCLUSIVE_INCLUSIVE(前后都包括)。

SpannableStringBuilder builder=new SpannableStringBuilder(m_txt_price+txt_price_end);
StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
ForegroundColorSpan red=new ForegroundColorSpan(Color.RED);
AbsoluteSizeSpan zt=new AbsoluteSizeSpan(38);
builder.setSpan(zt, 0, m_txt_price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //字体

builder.setSpan(red, 0, m_txt_price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//颜色
builder.setSpan(bss, 0, m_txt_price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//字体格式,粗体
txt_price.setText(builder);

或者直接转html
String html="html格数文本";
txt_price.setText(Html.fromHtml(html)); //xml解析

 
原文地址:https://www.cnblogs.com/hui413027075/p/6502551.html