TextView与彩色字体

时间:2017-02-25 20:27:44

标签: android paragraph

Lorem ipsum dolor 是一个textview,其余部分是独立的。

如何在Android中执行此操作?

https://stats.stackexchange.com/a/88993/16263

1 个答案:

答案 0 :(得分:0)

有多种方式,但我最喜欢这个 -

TextView TV = (TextView)findViewById(R.id.mytextview01);
 Spannable word = new SpannableString("Your message");        

 word.setSpan(new ForegroundColorSpan(Color.BLUE), 0, word.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

 TV.setText(word);
 Spannable wordTwo = new SpannableString("Your new message");        

 wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 TV.append(wordTwo);

Source