答案 0 :(得分:0)
我建议关注此链接,我相信会告诉您如何。
Android: Different colours for different characters in EditText
答案 1 :(得分:0)
您可以使用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);
答案 2 :(得分:0)
试试这个我认为这会对你有所帮助:
if(edit_text.length> limit){edit_text.settextcolor("your color code");}