Android TextView Highlight highlight(int start, int end, TextView text)

Here you can find the source of highlight(int start, int end, TextView text)

Description

hightlight text

Parameter

Parameter Description
start a parameter
end a parameter
text a parameter

Declaration

public static void highlight(int start, int end, TextView text) 

Method Source Code

//package com.java2s;

import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;

import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

public class Main {
    /**/* w  ww . j  a  v  a2  s. co m*/
     * hightlight text
     * @param start
     * @param end
     * @param text
     */
    public static void highlight(int start, int end, TextView text) {
        SpannableStringBuilder spannable = new SpannableStringBuilder(text
                .getText().toString());
        ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);
        spannable.setSpan(span, start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setText(spannable);
    }
}