[我要改變編輯文本顏色,當字符的限制此圖像中超過就像]如何在字符限制超過時更改編輯文本字體顏色?
[[1]:http://i.stack.imgur.com/fHTCA.png]
- 如何給基於文本更改監聽器這樣的效果???
[我要改變編輯文本顏色,當字符的限制此圖像中超過就像]如何在字符限制超過時更改編輯文本字體顏色?
[[1]:http://i.stack.imgur.com/fHTCA.png]
我建議按照這個鏈接,我相信告訴你如何。
Android: Different colours for different characters in EditText
您可以使用Spannable
:
EditText tv = (EditText)findViewById(R.id.tv);
Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers");
wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), 5, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(wordtoSpan);
或HTML格式Html.fromHtml
:
String text = "This is <font color='red'>red</font>. This is <font color='blue'>blue</font>.";
tv.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);
試試這個,我認爲這將幫助你:
if(edit_text.length> limit){edit_text.settextcolor("your color code");}
[Android EditText +設置一些顏色的單詞]可能的重複(http://stackoverflow.com/questions/10303166/android-edittext-set-some-words-in-colour) – Ajinkya