Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import android.widget.TextView;
import android.widget.TextView.BufferType;

public class Main {
    public static void setTextViewCharHilighted(TextView textView, String text, int startIndex, int endIndex,
            int color) {
        if (textView == null || text == null) {
            return;
        }

        if (startIndex < 0) {
            return;
        }

        if (endIndex > text.length()) {
            return;
        }

        textView.setText(text, BufferType.SPANNABLE);

        Spannable span = (Spannable) textView.getText();
        if (span == null) {
            return;
        }

        span.setSpan(new ForegroundColorSpan(color), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}