1

I am creating a search engine like application in android and i want to know how to highlight the searched word in a listview like in this link.. http://androidbible.blogspot.com/2010/12/color-highlight-and-whole-word-search.html thank you in advance for those who want to help...

Mordiggian
  • 265
  • 1
  • 3
  • 11

1 Answers1

3

I think you can try SpannableString

Just a demo below.

    TextView tv = (TextView) findViewById(R.id.textView1);
    SpannableString str = new SpannableString("hello");
    BackgroundColorSpan span = new BackgroundColorSpan(Color.YELLOW);
    str.setSpan(span, 0, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
    tv.setText(str);
Changwei Yao
  • 13,051
  • 3
  • 25
  • 22