Android examples for android.text:SpannableString
highLight String with SpannableStringBuilder
import android.content.Context; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.ForegroundColorSpan; import android.util.Log; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; public class Main{ public static SpannableStringBuilder highLightStr(String str, String highLightStr, int color) { int start = str.indexOf(highLightStr); SpannableStringBuilder style = new SpannableStringBuilder(str); style.setSpan(new ForegroundColorSpan(color), start, start + highLightStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return style; }// w w w .j a v a2 s. c o m }