In xml based layouts we can set app:autoSizeTextType="uniform" in the edit text to auto size the text font. But similar feature is not available in compose TextField. Please suggest if there is any alternative way of doing it.
Asked
Active
Viewed 1,193 times
3
Phil Dukhov
- 67,741
- 15
- 184
- 220
Abhishek
- 86
- 6
-
1Does [this](https://stackoverflow.com/questions/63971569/androidautosizetexttype-in-jetpack-compose/66490475#66490475) help? – Code Poet Nov 04 '22 at 14:48
-
1https://gist.github.com/bmc08gt/e890e63124846e02f6afb38ee27e9f9c – CommonsWare Mar 10 '23 at 22:58
-
1Try the below solution. It's works for me. [link](https://stackoverflow.com/a/64380602/9794122) – Jay Nirmal Mar 14 '23 at 08:01
-
Thanks gangs for you help – Pritesh Patel Mar 17 '23 at 14:03
1 Answers
1
You can try following solution
@Composable
fun Int.scaledSp(): TextUnit {
val value: Int = this
return with(LocalDensity.current) {
val fontScale = this.fontScale
val textSize = value / fontScale
textSize.sp
}
Pritesh Patel
- 678
- 17
- 35