2014-02-11 90 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);

相關問題