Bold text - Jetpack Compose
In Jetpack Compose, you can use fontWeightAdjustment
property on Android 12 and higher. The property returns an integer between 1
and 1000
, which indicates the current user preference for increasing font weight. The constant FontStyle.FONT_WEIGHT_BOLD
has a value of 700
.
@Composable
fun prefersBoldFont(): Boolean {
val context = LocalContext.current
val configuration = LocalConfiguration.current
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
false
} else {
configuration.fontWeightAdjustment >= FontStyle.FONT_WEIGHT_BOLD
}
}