colorize text by Spannable - Android android.text

Android examples for android.text:SpannableString

Description

colorize text by Spannable

Demo Code

import android.text.Spannable;
import android.text.style.ForegroundColorSpan;

public class Main{

    public static Spannable colorize(String text, int color) {
        Spannable spannable = Spannable.Factory.getInstance().newSpannable(
                text);//from  ww  w  .ja  v  a  2  s. c o m
        spannable.setSpan(new ForegroundColorSpan(color), 0, text.length(),
                0);
        return spannable;
    }

}

Related Tutorials