android textview 设置不同的颜色和大小

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;

 

posted on 2015-11-25 13:46  Joyfulmath  阅读(872)  评论(2编辑  收藏  举报

导航