Daniele B
04/03/2024, 10:24 AMmohamed rejeb
04/03/2024, 10:37 AMDaniele B
04/03/2024, 10:40 AMDaniele B
04/03/2024, 11:29 AMval screenDensity = LocalDensity.current.density
val textSp = (screenDensity * textDp.value).sp
But actually the system font size settings doesn't affect the screenDensity.
I would like to set the correct Sp, starting from a Dp value, based on the actual system font size settings.
In other words, I would like the text to have the same size, no matter what is the system font size settings.
Any idea?Daniele B
04/03/2024, 11:50 AMval fontScale = LocalDensity.current.fontScale
val textSp = fontSize / fontScale
Daniele B
04/03/2024, 12:36 PMfun TextUnit.scaleIndependent() : TextUnit {
return this / LocalDensity.current.fontScale
}
so, I can convert easily any Sp to be scale independent:
val fontSize = 14.sp.scaleIndependent()
romainguy
04/03/2024, 3:32 PMDaniele B
04/04/2024, 4:51 AM