Create Spannable String from string and color - Android android.text

Android examples for android.text:SpannableString

Description

Create Spannable String from string and color

Demo Code

import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import java.util.List;

public class Main{

    public static SpannableString getSpannableString(String str, int color) {
        SpannableString span = new SpannableString(str);
        span.setSpan(new ForegroundColorSpan(color), 0, span.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return span;
    }// www . j a  v a 2s.com

}

Related Tutorials