-3

I am displaying text in a textview without using toString(), to keep the formatting(bold, underline, italics) within the text. But now I want to set different font sizes to _etheadertext ,_etheadertext3 etc..

String header = _etheadertext.getText() + "\n" + _etheadertext3.getText() + "\n" + _etheadertext4.getText() + "\n" + _etheadertext5.getText();
Swayam
  • 16,294
  • 14
  • 64
  • 102
Sarah
  • 45
  • 7
  • It's span feature https://developer.android.com/guide/topics/text/spans , but this may be the one for you. https://stackoverflow.com/questions/7919173/android-set-textview-textstyle-programmatically – Toris Jan 27 '19 at 10:36
  • It doesn't answer my questions. I can't put set typeface because it's not a textview – Sarah Jan 27 '19 at 12:12
  • Please upload layout xml or show which class you are using for _etheadertext etc. You've wrote "I m displaying text in a textview" in the question. Isn't it a textview? – Toris Jan 27 '19 at 12:14

1 Answers1

0

You can use text Spans to apply formatting to parts of a string.

SpannableString spannablecontent=new SpannableString(content.toString());
//set a Style Span to apply Typeface style    
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 
                             0,spannablecontent.length(), 0);

You can set RelativeSizeSpan to change the text sizes if required.

And then finally, set the spanned string in a TextView.

mTextView.setText(spannablecontent);
Swayam
  • 16,294
  • 14
  • 64
  • 102