"Closes" the specified tags on a Spannable by updating the spans to be endpoint-exclusive so that future text appended to the end will not take on the same styling. - Android Graphics

Android examples for Graphics:Spannable

Description

"Closes" the specified tags on a Spannable by updating the spans to be endpoint-exclusive so that future text appended to the end will not take on the same styling.

Demo Code


import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;

public class Main{
    /**//from   w  ww .  j ava2 s.co m
     * "Closes" the specified tags on a Spannable by updating the spans to be
     * endpoint-exclusive so that future text appended to the end will not take
     * on the same styling. Do not call this method directly.
     */
    private static void closeTags(Spannable text, Object[] tags) {
        int len = text.length();
        for (Object tag : tags) {
            if (len > 0) {
                text.setSpan(tag, 0, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                text.removeSpan(tag);
            }
        }
    }
}

Related Tutorials