https://kotlinlang.org logo
Title
s

Stylianos Gakis

05/16/2023, 12:02 PM
Does compose text APIs contain a way to easily add some “superscript” text? Aka some section which is attached to the top, and is a bit smaller than the rest of the text. Example in thread. edit: (Yes it does, through annotated strings, super simple too, solution in thread.)
Something like this, so I can add that “2”superscript next to the “a” in block A2 of this sheet and so on.
Okay yeah I failed to google for it before, but turns out it’s very simple using an annotated string + a SpanStyle with BaselineShift.Superscript.
Text(
  text = buildAnnotatedString {
    append("Hello")
    withStyle(
      SpanStyle(
        baselineShift = BaselineShift.Superscript,
        fontSize = 16.sp,
      )
    ) {
      append(" superscript")
    }
  },
)
This outputs something like this [pic attached] already Found it in this SOE post.