2016-03-03 79 views

回答

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); 
0

試試這個,我認爲這將幫助你:

if(edit_text.length> limit){edit_text.settextcolor("your color code");}