在Android中设置TextView span的颜色 [英] Set color of TextView span in Android

查看:17
本文介绍了在Android中设置TextView span的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to set the color of just span of text in a TextView?

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

I would like to do something similar to the Twitter app, in which a part of the text is blue. See image below:


(来源:twimg.com)

推荐答案

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

Another answer would be very similar, but wouldn't need to set the text of the TextView twice

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

这篇关于在Android中设置TextView span的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆