2014-02-11 95 views

回答

0
Pattern pattern = Pattern.compile("tree"); 
Matcher matcher = pattern.matcher(yourTextViewText); 

final SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(yourTextViewText); 
final ForegroundColorSpan span = new ForegroundColorSpan(Color.RED); 
while (matcher.find()) { 
    spannableBuilder.setSpan(
     span, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
} 
yourTextView.setText(spannableBuilder); 

这将用RED颜色代替所有“树”字。

See More About Pattern Here

+0

非常感谢。我的问题解决了。 – user3270441

+0

并在你的代码中添加大胆的加法? – user3270441

0

要更改的文字,使用的颜色:

textview.setTextColor(Color.RED);

相关问题