Skip to content

Instantly share code, notes, and snippets.

@MuhSalmaNabila
Forked from pratamawijaya/TextHighlight.java
Created November 28, 2016 13:31
Show Gist options
  • Save MuhSalmaNabila/1ebe2e5540754ef3a3516f4f96ae78db to your computer and use it in GitHub Desktop.
Save MuhSalmaNabila/1ebe2e5540754ef3a3516f4f96ae78db to your computer and use it in GitHub Desktop.
TextHighlight.java
// digunakan untuk Highlight text yang sedang dicari
private void setColor(TextView view, String fulltext, String subtext, int color) {
view.setText(fulltext, TextView.BufferType.SPANNABLE);
Spannable str = (Spannable) view.getText();
int i = fulltext.indexOf(subtext);
str.setSpan(new ForegroundColorSpan(color), i, i + subtext.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment