4

I want to write a line in a TextView where the second word is a quarter of the size of the first word. In my string.xml file I used large and small and it did not work to the extent I want it to. I also tried changing the text size in the main.xml, but it only lets you do that once in a TextEdit. Any ideas?

Aaron
  • 4,042
  • 14
  • 76
  • 131

3 Answers3

4

If what you need is to specify different font sizes for the text in a TextView from XML you can assign a string like this:

<string name="hello"><big><big>Hello Big Text!</big></big>\n<small>Hello small text</small></string>

and use this string in the TextView. Note that the newline is '\n' instead of <br/>

<TextView
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:text="@string/hello" />
Diego Torres Milano
  • 61,192
  • 8
  • 106
  • 129
1

Take a look at this question: Is it possible to change the text color in a string to multiple colors in Java?

But instead of ForegroundColorSpan you should use TextAppearanceSpan or AbsoluteSizeSpan.

Community
  • 1
  • 1
inazaruk
  • 73,337
  • 23
  • 185
  • 156
0

Try using the fromHTML method of the HTML class.

This way you can format the string using basic HTML <font> tags

MrZander
  • 2,970
  • 1
  • 28
  • 47