textview实现多个文字着色和增加多个图片

代码如下:

public class StringColor {
    public static SpannableString setTextColor( @ColorInt int color, String text, String... colorText){
        SpannableString builder=new SpannableString(text);
        for (final String str :
                colorText) {
            int start=text.indexOf(str);
            int end=start+str.length();
            builder.setSpan(new ForegroundColorSpan(color),start,
                    end, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return builder;
    }
    
    public static SpannableStringBuilder setLeftImageText(String text, Drawable... drawables){
        SpannableStringBuilder builder=new SpannableStringBuilder();
        String iconTag = "[icon]";
        if (drawables!=null&&drawables.length>0){
            for (int i = 0; i 

 

你可能感兴趣的:(技巧,android)