Highlighting Text Color using Html.fromHtml() in Android?

sunil picture sunil · Apr 28, 2010 · Viewed 106.9k times · Source

I am developing an application in which there will be a search screen where user can search for specific keywords and that keyword should be highlighted. I have found Html.fromHtml method.

But I will like to know whether its the proper way of doing it or not.

Please let me know your views on this.

Answer

Christopher Orr picture Christopher Orr · May 30, 2010

Or far simpler than dealing with Spannables manually, since you didn't say that you want the background highlighted, just the text:

String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);