的TextView的跨度在Android中设置颜色 [英] Set color of TextView span in Android
本文介绍了的TextView的跨度在Android中设置颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以设置文字只是范围的颜色在一个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:
推荐答案
另一个答案是非常相似,但并不需要设置的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);
这篇关于的TextView的跨度在Android中设置颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文