Prevent system font scaling – Jetpack Compose


I am trying to restric the app from affected fro system font scaling. I had gone through many solutions but none helped. Most of them tell use dp instead of dp for text sizes but in compose we can use only sp if i am right as it expects a Text Unit.
Is there any right way to restrict font scaling in our app done with jetpack compose ? Please help .

(Solutions refered) :


You can have an extension for Int or Float like this

fun Int.scaledSp(): TextUnit {
    val value: Int = this
    return with(LocalDensity.current) {
        val fontScale = this.fontScale
        val textSize =  value / fontScale

You can add an extension parameter of Int

val Int.scaledSp:TextUnit
    @Composable get() =  scaledSp()

Text(text = "Hello World", fontSize = 20.scaledSp)

Answered By – Thracian

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published