set Colorful Text to TextView - Android User Interface

Android examples for User Interface:TextView

Description

set Colorful Text to TextView

Demo Code


//package com.java2s;

import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import android.widget.TextView;

public class Main {

    public static void setColorfulText(int startPos, int endPos,
            String text, int color, TextView tv) {
        SpannableStringBuilder builder = new SpannableStringBuilder(text);
        builder.setSpan(new ForegroundColorSpan(color), startPos, endPos,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setText(builder);//from  w  w  w  .  jav  a2  s . co  m
    }
}

Related Tutorials