一個(gè)TextView有不同樣式這里用的SpannableString來(lái)實(shí)現(xiàn)。如下圖所示的效果:
Paste_Image.png
上面的效果需要設(shè)置兩個(gè)樣式
<style name="money_style1">
<item name="android:textSize">12sp</item>
<item name="android:textStyle">normal</item>//正常字體
</style>
<style name="money_style2">
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>//加粗
</style>
String price=vh.price.getText().toString();
int len=price.length();
SpannableString spannableString=new SpannableString(price);
spannableString.setSpan(new TextAppearanceSpan(context,R.style.money_style1),0,1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new TextAppearanceSpan(context,R.style.money_style2),1,price.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new TextAppearanceSpan(context,R.style.money_style1),price.length()-1,price.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
vh.price.setText(spannableString);