var msp = SpannableString(txtv.text) var lowerStr = txtv.text.toString().toLowerCase() Log.d("shawnKeyWordSearch", "keyword:$keyword") val pattern: Pattern = Pattern.compile(keyword.toLowerCase()) val matcher: Matcher = pattern.matcher(lowerStr) while (matcher.find()) { val start: Int = matcher.start() val end: Int = matcher.end() msp.setSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.water_blue)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) } txtv.text = msp
shawn