Hey, I'm trying to replicate a UI in Jetpack Compo...
# compose-android
v
Hey, I'm trying to replicate a UI in Jetpack Compose where I display an instruction like:
Copy code
1. Click the button below to copy the one time code.
Here are the style requirements: • The number
1.
should be in a different color, bigger in size. • List item
1.
spacing between
1
and dot
.
• The phrase "one time code" should be bold. • The rest of the sentence should use normal styling. What is the best way to structure and style this text using Jetpack Compose? Should I use
AnnotatedString
,
TextSpan
, or is there a better approach?
Copy code
@Composable
fun StepItem(number: String, text: String, styleCode: String) {
    Row(verticalAlignment = <http://Alignment.Top|Alignment.Top>, modifier = Modifier.padding(start = 20.dp)) {
        Text(
            text = number,
            style = MaterialTheme.typography.bodyMedium.copy(
                fontWeight = FontWeight.SemiBold,
                color = MaterialTheme.colorScheme.primary,
                fontSize = 20.sp
            ),
        )
        Text(
            buildAnnotatedString {
                append(text)
                withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
                    append(styleCode)
                }
            },
            style = MaterialTheme.typography.bodyMedium
        )
    }
}
Expected Output
Actual Output