I have to put in the same textView a string with substrings of different sizes and colors. How can I do?
Asked
Active
Viewed 1,333 times
2
-
write html code and use Html.fromHtml() method – Biraj Zalavadia Feb 06 '14 at 09:24
4 Answers
2
You need to create a String with HTML tags and set this String to TextView as Html.fromHtml like below:
((TextView) findViewById(R.id.txt)).setText(
Html.fromHtml("<Font color=\'" + "#457548"
+ "'\" >" + "your text"
+ "</Font>"), TextView.BufferType.SPANNABLE)
More information go to: how-display-html-android
M D
- 47,398
- 9
- 92
- 112
0
You could attach html notation to the text, or put a textview for each different size and color in a linearlayout, why does it have to be strictly in one textview?
Angmar
- 599
- 4
- 9
0
If you don't want to use HTML, you can use spannables in a custom view.
Have a look at some old questions those can give you some hints:
Community
- 1
- 1
Simone Casagranda
- 1,219
- 17
- 26
0
Android has SpannableString that can be set in a textView. Each SpannableString can have a different color, font , onCLick() and so on. Multiple SpanableStrings can be set to a single texview.
Aditya Kushwaha
- 839
- 6
- 12