2

In Android, it is easy to set a style for an entire TextView:

textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);

Is there a way to set a style for specific words (or characters) within the view? I would like to generate a line like:

Year:2012, Language:Armenian, Subtitles:English

Community
  • 1
  • 1
Adam Matan
  • 128,757
  • 147
  • 397
  • 562

3 Answers3

2

Yes, you can use Html.fromHtml to change style of specific word as:

textview.setText(Html.fromHtml("<b>" + Year: + "</b>"+"2012,
                  "+"<b>" + Language: + "</b>"+":Armenian,"
                  "+"<b>" + Subtitles: + "</b>"+":English"));

EDIT :

if you have any issue to use Html.fromHtml(...) then you can go for SpannableString for Creating an String with different fonts,colors or style.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
1
textView.setText(Html.fromHtml(
    "<b> Year </b>2012<br> <b> Language </b>"));
hgoebl
  • 12,637
  • 9
  • 49
  • 72
jnr
  • 229
  • 2
  • 5
0

for this you can use HTML format of text like below.

  textView.setText(Html.fromHtml("<b>Year:</b>2012,<b>Language</b>"));
Raj
  • 1,843
  • 2
  • 21
  • 47