Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rid of default extra padding for Texts in Jetpack Compose?

I can't find a way for such a simple change:

Texts in jetpack compose have a default padding on top and bottom like this:

enter image description here

How can I remove that? I want the border of the Text Composable to be at the top and bottom end of the letters, just like it is the case on the right and the left of the text

If I use Modifier.height(), letters like g get cut off, but I want them to still be visible while other Composables like Column ignore those extra heights


After setting deprecated includeFontPadding to false, the padding amount gets decreased, but still exists:

enter image description here


How can that padding be reduced to zero?

like image 974
user19095510 Avatar asked Oct 18 '25 15:10

user19095510


1 Answers

Is it possible that you are using an old version of Compose? This issue was fixed in Version 1.2.0-alpha05: "Text: includeFontPadding is now turned off by default." Try upgrading to version 1.3.3.

EDIT: It looks like it was turned on again in 1.2.0-beta01. According to the issueTracker: "RelNote: "Turned on default includeFontPadding. It is possible to turn off the includeFontPadding using TextStyle.platformTextStyle attribute. In the near future we will change the default behavior however until that time this allows us to better integrate line height improvements (aosp/2058653) and solve TextField clipping issues."

The workaround is to use platformStyle. You could also comment on the issueTracker and star it if you wish.

like image 119
Code Poet Avatar answered Oct 20 '25 05:10

Code Poet



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!