publicabstractvoidsetSpan(Object what, int start, int end, int flags)
Attach the specified markup object to the range start…end
of the text, or move the object to that range if it was alreadyattached elsewhere. See
Spanned
for an explanation ofwhat the flags mean. The object can be one that has meaning onlywithin your application, or it can be one that the text system willuse to affect text display or behavior. Some noteworthy ones arethe subclasses
of CharacterStyle
andParagraphStyle
, andTextWatcher
andSpanWatcher
.
SpannableString s = new SpannableString(getResources().getString(R.string.linkify));
Pattern p = Pattern.compile("abc");
Matcher m = p.matcher(s);
while (m.find()) {
int start = m.start();
int end = m.end();
s.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
tv.setText(s);