Hey guys =) android newbie here. I'm trying to write a sentence in TextView, and I only want one word in the sentence to be in italics. for e.g. android:text="my name isn't Amber?" ==> I want only the word "isn't" to be italicised. Any help would be appreciated. TIA!
Asked
Active
Viewed 169 times
0
-
you can use html format see in link for html format https://stackoverflow.com/questions/2116162/how-to-display-html-in-textview – Sanjay Kumar Jan 16 '18 at 15:09
2 Answers
2
One way to achieve that is using a Spannable, A StyleSpan
with Typeface.ITALIC
on isn't
, in your case, and then setting the resulting CharSequence
to the TextView
. Another way is to use an Html
string, enclosing isn't
between <i></i>
, and formatting it with Html.fromHtml

Blackbelt
- 156,034
- 29
- 297
- 305
0
You can use the plain old html tags. This should do the trick:
String txt = "My name <i>isn't</i> Amber";
myTextView.setText(Html.fromHtml(txt,TO_HTML_PARAGRAPH_LINES_CONSECUTIVE));

Dark.Rider
- 381
- 1
- 4
- 17