Daniele B
10/22/2020, 9:47 AMText composable seems to only accept sp font-sizes, and not dp.
There are some situations, where using sp (i.e. allowing the system to adjust the text size according to user general settings) is going to break a layout. So you want to couple the text to the layout (e.g. when you want to display a text on just one line, which has a limited width).
On the traditional Android view system, it was possible to use dp instead of sp for text.
How can I deal with this in JetpackCompose ?cheapmon
10/22/2020, 9:55 AMsomeDp.value.sptieskedh
10/22/2020, 10:04 AMval sp = with(DensityAmbient.current){
100.dp.toSp()
}Daniele B
10/22/2020, 11:33 AMsomeDp.value.sptieskedh
10/22/2020, 12:35 PMDaniele B
10/22/2020, 12:50 PMZach Klippenstein (he/him) [MOD]
10/22/2020, 1:48 PMDaniele B
10/22/2020, 1:59 PMZach Klippenstein (he/him) [MOD]
10/22/2020, 2:08 PMDaniele B
10/22/2020, 2:31 PMDaniele B
10/22/2020, 2:32 PMZach Klippenstein (he/him) [MOD]
10/22/2020, 2:36 PMDaniele B
10/23/2020, 3:45 PMsomeDp.value.sp still adjusts the size when you change Font size or Display size in the phone settingsDaniele B
10/23/2020, 4:03 PMcurrent value, which is understandable.
I found a solution by creating a composable like this:
@Composable
fun fixedFont(dp : Dp) : TextUnit {
return with(DensityAmbient.current) { dp.toSp() }
}
and using it like this:
Text(text = "mytext", fontSize = fixedFont(12.dp))Daniele B
10/23/2020, 4:06 PMDaniele B
10/23/2020, 4:37 PMBottomNavigationItem s
you don’t want it to vary based on the device textsize settings.Zach Klippenstein (he/him) [MOD]
10/23/2020, 4:46 PM