android - 在Android中设置TextView span的颜色

是否可以在 TextView 中设置仅文本跨度的颜色?

我想做一些类似于 Twitter 应用程序的事情,其中​​一部分文本是蓝色的。见下图:


(来源:twimg.com)

最佳答案

另一个答案将非常相似,但不需要设置 TextView 的文本两次

TextView TV = (TextView)findViewById(R.id.mytextview01);

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

TV.setText(wordtoSpan);

https://stackoverflow.com/questions/3282940/

相关文章:

python - 如何在 Python 中打破这条长线?

java - 如何格式化带有前导零的Java字符串?

windows - 在 Windows 批处理脚本中格式化日期和时间

c# - 格式化 XML 字符串以打印友好的 XML 字符串

jquery - 使用 jQuery 将文本插入 textarea

python - 格式化没有尾随零的 float

java - 如何在 Java 中打印带有 2 位小数的 float ?

c# - 如何在 .NET 中使用自定义格式对 TimeSpan 对象进行 String.Forma

python - 如何自定义 Python 日志记录的时间格式?

c# - 自定义数字格式字符串以始终显示符号