Is it possible to set the color of just span of text in a TextView?
I would like to do something similar to the Twitter app, in which a part of the text is blue. See image below:
Is it possible to set the color of just span of text in a TextView?
I would like to do something similar to the Twitter app, in which a part of the text is blue. See image below:
If you want more control, you might want to check the
TextPaint
class. Here is how to use it:Output:
Here is a little help function. Great for when you have multiple languages!
There's a factory for creating the Spannable, and avoid the cast, like this:
Set your
TextView
´s text spannable and define aForegroundColorSpan
for your text.Another answer would be very similar, but wouldn't need to set the text of the
TextView
twice