Advertisement

Responsive Advertisement

Superscript/ Subscript In jetpack compose android

  • 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





 

Post a Comment

0 Comments