How can I make text in TextView in two different sizes?

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 big and small, and it did not work as much as I want. I also tried resizing the text in main.xml, but it only allows it to be done once in TextEdit. Any ideas?

+4
source share
3 answers

If you need to specify different font sizes for text in a TextView from XML, you can assign this line:

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

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

 <TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="match_parent" android:text="@string/hello" /> 
+4
source

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

Instead of ForegroundColorSpan you should use TextAppearanceSpan or AbsoluteSizeSpan .

+1
source

Try using the fromHTML method of the HTML class.

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

0
source

Source: https://habr.com/ru/post/1385989/


All Articles