textview highlight

1.SpannableStringBuilder
example:
String str = "highlight me!";
String highLight = "me";
int start = str.indexOf(highLight);
SpannableStringBuilder style=new SpannableStringBuilder(str);
style.setSpan(new BackgroundColorSpan(Color.RED), start, start + highLight.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 textview.setText(style);


2.html
example:
tv.setText(Html.fromHtml("highlight <font color=\"#ff0000\">me</font>!"))

你可能感兴趣的:(java,html)