- Step 1
Add this function.@Composable
fun SuperScriptText(
normalText: String,
superText: String
) {
Text(buildAnnotatedString {
withStyle(
style = SpanStyle(
fontSize = MaterialTheme.typography.titleLarge.fontSize
)
) {
append(normalText)
}
withStyle(
style = SpanStyle(
fontSize = MaterialTheme.typography.headlineMedium.fontSize,
fontWeight = FontWeight.Normal,
baselineShift = BaselineShift.Superscript
),
) {
append(superText)
}
})
}
- Step 2
For preview
use this@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
BasicsCodelabTheme {
Column(modifier = Modifier.fillMaxSize()) {
SuperScriptText("Hii ", "Roshan")
}
}
} - Screenshot Attached
0 Comments