Multiple Text Color in Single TextView | Sololearn: Learn to code for FREE!

+4

Multiple Text Color in Single TextView

How to Show specific text in Color Text = hello this is example of text need output like this = hello : in blue color this : in red color is example : white color of text : green color like IDE and Code Editor i wanna this kind of Text in my Android Studio project

1/25/2021 9:45:10 AM

Saurya

8 Answers

New Answer

+3

https://code.sololearn.com/ciQPuk8N1ch0/?ref=app i have solved yet 🙂 by replacing specific text with Html class in Android studio

+2

+2

Saurya ya, seems like good solution using HTML spans, but is that dynamic, how you gonna change or perform action with those TextView in runtime.

+2

Saurya seems ligit to me, I'm not really into html classs. Is this only for text markup or have other usefulness, how about complex text highlighting, a text which acts as button or so on. Don't get me wrong, seriously I'm not downvoting your answers.

+1

You can do it by html encode I am giving a example in xamarin android Example <span style=color:blue>hello</span> <span style=color:red>this</span> <span style=color: white>is example</span> <span style=color: green>of text</span> <Lable Text="&lt;span style=color:blue&gt;hello&lt;/span&gt; &lt;span style=color:red&gt;this&lt;/span&gt; &lt;span style=color: white&gt;is example&lt;/span&gt; &lt;span style=color: green&gt;of text&lt;/span&gt;" Type="html" /> This code provide same result as you expect

+1

By creating a method if specific Word found in Text then replace that Specific text with Html.fromhtml() method

+1

then after replacing from Html class in color set text in TextView

+1

Saurya simply don't delete this stuffs, as in future someone may have same problem, this might be helpful. People will learn something from this.