如何用定時器逐個單詞更改段落單詞的顏色。像在第一秒我想改變的在下面的段落中的顏色,之後文本的第5秒變色,後8日第二個變化顏色會等等... 。TextView:如何動態更改段落中某個單詞的顏色
The text will be wrapped in tags, and displayed in a monospaced font.
如何用定時器逐個單詞更改段落單詞的顏色。像在第一秒我想改變的在下面的段落中的顏色,之後文本的第5秒變色,後8日第二個變化顏色會等等... 。TextView:如何動態更改段落中某個單詞的顏色
The text will be wrapped in tags, and displayed in a monospaced font.
只是使用Timer並相應地改變你的編輯文本的字體顏色和停止定時器焦點丟失。
我認爲你可以做這樣的事情:
斯普利特款的話使用方法:
split(String separator);// it will return an array of Strings
//in your case you will do somthing like this
myWords = paragraph.split(" ");// the separator is the space
然後,你可以使用的方法來colorate你想要的那些什麼都通過使用該方法的話:
myNewParagraph.append(HTML.fromHtml("<font color...>... Your HTML Code to colorate your Text"));
,當你完成着色每一個字,你更新的TextView來顯示彩色
01新文本希望它有幫助
您可以使用跨度來控制文本的外觀。看看Spannable和CharacterStyle。
這裏是一個例子。當然你需要把它放在某種計時器中。
Spannable spannableText = getSpannableText(yourTextView);
spannableText.setSpan(new TextAppearanceSpan(...), wordStart, wordEnd)
yourTextView.setText(spannableText);
private Spannable getSpannableText(TextView tv) {
CharSequence cs = tv.getText();
if (cs instanceof Spannable) {
return (Spannable)cs;
} else {
return SpannableString.valueOf(cs);
}
}