Here you can find the source of hightLinghtString(String destStr, String subStr, int color)
public static SpannableStringBuilder hightLinghtString(String destStr, String subStr, int color)
//package com.java2s; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.ForegroundColorSpan; public class Main { public static SpannableStringBuilder hightLinghtString(String destStr, String subStr, int color) { SpannableStringBuilder style = new SpannableStringBuilder( null == destStr ? "" : destStr); if (null == destStr || "".equals(destStr) || "".equals(subStr)) { return style; }//from w ww.j av a 2 s. c o m int start = destStr.lastIndexOf(subStr); if (start != -1) { style.setSpan(new ForegroundColorSpan(color), start, start + subStr.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE); } return style; } }