@@ -0,0 +1,2196 @@
+package com.stupid.method.util;%0A%0Aimport java.util.LinkedList;%0A%0Aimport android.text.SpannableStringBuilder;%0Aimport android.text.Spanned;%0Aimport android.text.style.ForegroundColorSpan;%0A%0A/**%0A * %E5%A4%8D%E5%88%B6%E8%BF%87%E6%9D%A5,%E5%A4%8D%E5%88%B6%E8%BF%87%E5%8E%BB....%0A * %0A * */%0Apublic final class TextColor implements Cloneable %7B%0A%09private static final class TextColorData implements Cloneable %7B%0A%0A%09%09public static final TextColorData mColorData = new TextColorData();%0A%0A%09%09public static TextColorData newInstance() %7B%0A%09%09%09try %7B%0A%09%09%09%09return (TextColorData) mColorData.clone();%0A%09%09%09%7D catch (CloneNotSupportedException e) %7B%0A%09%09%09%09return new TextColorData();%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09int end;%0A%09%09int flags;%0A%09%09int start;%0A%09%09String tex;%0A%09%09Object what;%0A%0A%09%09public TextColorData() %7B%0A%0A%09%09%7D%0A%0A%09%09public TextColorData rest(String tex, Object what, int start, int end,%0A%09%09%09%09int flags) %7B%0A%09%09%09this.tex = tex;%0A%09%09%09this.what = what;%0A%09%09%09this.start = start;%0A%09%09%09this.end = end;%0A%09%09%09this.flags = flags;%0A%0A%09%09%09return this;%0A%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public String toString() %7B%0A%0A%09%09%09return String.format(%22tex=%25s;what=%25s;start=%25s;end=%25s;flags=%25s;%22,%0A%09%09%09%09%09tex, what, start, end, flags);%0A%09%09%7D%0A%09%7D%0A%0A%09StringBuilder builder;%0A%0A%09LinkedList%3CTextColorData%3E textColorDatas;%0A%0A%09public TextColor() %7B%0A%09%09builder = new StringBuilder(10);%0A%09%09textColorDatas = new LinkedList%3CTextColorData%3E();%0A%09%7D%0A%0A%09public TextColor append(String str, Object what, int flags) %7B%0A%09%09int length = builder.length();%0A%09%09builder.append(str);%0A%09%09textColorDatas.add(TextColorData.newInstance().rest(str, what, length,%0A%09%09%09%09length + str.length(), flags));%0A%0A%09%09return this;%0A%09%7D%0A%0A%09public TextColor appendTextColor(String txt, int color) %7B%0A%09%09if (StringUtils.isEmpty(txt))%0A%09%09%09return this;%0A%0A%09%09int length = builder.length();%0A%09%09builder.append(txt);%0A%09%09textColorDatas.add(TextColorData.newInstance().rest(txt,%0A%09%09%09%09new ForegroundColorSpan(color), length, length + txt.length(),%0A%09%09%09%09Spanned.SPAN_EXCLUSIVE_INCLUSIVE));%0A%09%09return this;%0A%09%7D%0A%0A%09@Override%0A%09protected Object clone() throws CloneNotSupportedException %7B%0A%0A%09%09return super.clone();%0A%09%7D%0A%0A%09public SpannableStringBuilder toStyle() %7B%0A%0A%09%09SpannableStringBuilder style = new SpannableStringBuilder(builder);%0A%0A%09%09for (TextColorData item : textColorDatas) %7B%0A%0A%09%09%09style.setSpan(item.what, item.start, item.end, item.flags);%0A%09%09%7D%0A%0A%09%09return style;%0A%09%7D%0A%7D%0A

add Textview text color