Code example for StyleSpan

0
    } 
 
    private static int format1(String text, int start, StringBuilder sb, List<StyleWithRegion> styles) {
        int end = text.indexOf('`', start);
        if(end != -1) {
            styles.add(new StyleWithRegion(new StyleSpan(Typeface.BOLD), sb.length(), sb.length()+end-start));
            sb.append(text.substring(start,end));
        } else { 
            end = start;
        } 
        return end;
    } 
 
    private static int format2(String text, int start, StringBuilder sb, List<StyleWithRegion> styles) {
        int end = text.indexOf('}', start);
        if(end != -1) {
            styles.add(new StyleWithRegion(new StyleSpan(Typeface.BOLD), sb.length(), sb.length()+end-start));
            styles.add(new StyleWithRegion(new ForegroundColorSpan(Color.YELLOW), sb.length(), sb.length()+end-start));
            sb.append(text.substring(start,end));
        } else {