Highlight Text in TextView or WebView

enable TextView’s Spannable storage!
by default Spannable storage in EditText is true.

so

TextView myTV = (TextView)findViewById(R.id.textView1);
String  textString = "StackOverFlow Rocks!!!"; 
Spannable spanText = Spannable.Factory.getInstance().newSpannable(textString);
spanText.setSpan(new BackgroundColorSpan(0xFFFFFF00), 14, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTV.setText(spanText);

Leave a Comment