Code example for SpannableStringBuilder

Methods: getSpanStartlengthremoveSpansetSpan

0
        int len = text.length();
        text.setSpan(new Font(parsedColor != null ? parsedColor : color, face), len, len, Spanned.SPAN_MARK_MARK);
    } 
 
    private static void endFont(SpannableStringBuilder text) {
        int len = text.length();
        Object obj = getLast(text, Font.class);
        int where = text.getSpanStart(obj);
 
        text.removeSpan(obj);
 
        if (where != len) {
            Font f = (Font) obj;
 
            if (!TextUtils.isEmpty(f.mColor)) {
                if (f.mColor.startsWith("@")) {
                    Resources res = Resources.getSystem();
                    String name = f.mColor.substring(1);
                    int colorRes = res.getIdentifier(name, "color", "android");
                    if (colorRes != 0) {
                        ColorStateList colors = res.getColorStateList(colorRes);
                        text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    } 
                } else { 
                    int c = getHtmlColor(f.mColor);
                    if (c != -1) {
                        text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    } 
                } 
            } 
 
            if (f.mFace != null) {
                text.setSpan(new TypefaceSpan(f.mFace), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } 
        } 
    } 
 
    private static void startA(SpannableStringBuilder text, Attributes attributes) {
Stop searching for code, let great code find you!  Add Codota to your java IDE