同一个textview设置不同文字样式

来源:互联网 发布:python beaker 编辑:程序博客网 时间:2024/05/01 00:43

一、定义俩个不同的样式

<style name="business_price_text_gray">    <item name="android:textSize">@dimen/x28</item>    <item name="android:textColor">@color/c_666666</item></style><style name="business_price_text_orange">    <item name="android:textSize">@dimen/x32</item>    <item name="android:textColor">#ff4000</item></style>


二、设置文字

SpannableString styledText = new SpannableString(goodsprice);styledText.setSpan(new TextAppearanceSpan(mContext, R.style.business_price_text_orange), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);styledText.setSpan(new TextAppearanceSpan(mContext, R.style.business_price_text_gray), length-3, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);tv_price.setText(styledText, TextView.BufferType.SPANNABLE);


0 0
原创粉丝点击