2014-12-19 70 views
-1

我在論壇尋找答案,我試着這樣做,但由於某種原因,顏色沒有改變,有沒有什麼我做錯了?添加一個字符串到textView,但改變它的顏色

SpannableString wordtoSpan = new SpannableString(songSelected); 
     wordtoSpan.setSpan(
      new ForegroundColorSpan(getResources().getColor(R.color.red)), 
      wordtoSpan.length()-1, 
      wordtoSpan.length(), 
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
     selected_song.setText("Selected song is: "+ wordtoSpan); 

回答

0

使用這樣

String styledText = "This is <font color='red'>simple</font>."; 
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE); 
相關問題