![android textview 设置不同的颜色和大小 android textview 设置不同的颜色和大小](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
1.定义不同的style
<style name="approval_detail_info_style1">
<item name="android:textSize">@dimen/sp13</item>
<item name="android:textColor">#666666</item>
</style> <style name="approval_detail_info_style2">
<item name="android:textSize">@dimen/sp14</item>
<item name="android:textColor">#333333</item>
</style>
2.设置和使用style
SpannableString styledText = new SpannableString(string);
styledText.setSpan(new TextAppearanceSpan(context, style1), 0, target, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
styledText.setSpan(new TextAppearanceSpan(context, style2), target+1, string.length()-1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
return styledText;