Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose Text fontSize behaviour

I'm learning android native with Jetpack Compose, and when I want to assign the font size of a text, I find two ways to do it, with the fontSize property and with the TextStyle.fontSize property, however, the two have a different behavior, the height of the line changes depending on which property I assign:

enter image description here enter image description here

I would like to know why this happens and which of the two options I should continue to use, thank you very much.

like image 849
Daniel Valencia Avatar asked Oct 21 '25 03:10

Daniel Valencia


1 Answers

The main difference in behavior between fontSize and TextStyle.fontSize is how they interact with other text styling properties. When you set fontSize directly on the Text composable, it applies the size directly without considering any other text styles. On the other hand, when you set TextStyle.fontSize, it applies the font size as part of the text style, which may adjust the height of the line and affect how the text is rendered, especially if you have other text styles applied.

In general, if you only want to set the font size without any additional styling, using the fontSize property directly on the Text composable is the straightforward approach.

like image 162
Haroon Avatar answered Oct 22 '25 18:10

Haroon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!