Change text color of a substring
TextView textView = (TextView) view.findViewById(R.id.textView);
String text = getString(R.string.foo);
textView.setText(text, TextView.BufferType.SPANNABLE);
Spannable spannable = (Spannable) textView.getText();
String substring = getString(R.string.substring);
int start = text.indexOf(substring);
int end = start + substring.length();
int red = getResources().getColor(R.color.red);
spannable.setSpan(new ForegroundColorSpan(red), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Written by Kamil Tusznio
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
Related Tags
#android
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#