Create Spannable String from text, color, start end - Android android.text

Android examples for android.text:SpannableString

Description

Create Spannable String from text, color, start end

Demo Code

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static SpannableString getSpecialSpannableString(String color,
            String text, int start, int end) {
        SpannableString mSpannableString = new SpannableString(text);

        mSpannableString.setSpan(//  w  w w . j  a v a2s.  c om
                new ForegroundColorSpan(Color.parseColor(color)), start,
                end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return mSpannableString;
    }

}

Related Tutorials