Android 向textView添加字符串,但更改其颜色
我在论坛上寻找答案,我试着这样做,但由于某种原因,颜色没有改变,有什么我做错了吗Android 向textView添加字符串,但更改其颜色,android,layout,textview,Android,Layout,Textview,我在论坛上寻找答案,我试着这样做,但由于某种原因,颜色没有改变,有什么我做错了吗 SpannableString wordtoSpan = new SpannableString(songSelected); wordtoSpan.setSpan( new ForegroundColorSpan(getResources().getColor(R.color.red)), wordtoSpan.length()-1,
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);
像这样使用
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
String styledText=“这很简单。”;
textView.setText(Html.fromHtml(styledText),textView.BufferType.SPANNABLE);