I have this in design mockups. How would I go abou...
# compose
d
I have this in design mockups. How would I go about adding white background to the text? I have tried doing two
Text
composables in the
Box
, with the former having
+ 1.sp
, but it doesn't align as perfectly as in the screenshot.
a
is a different approach
d
that's more promising, thank you!
s
Afaik @Halil Ozercan is working on stroke
[deleted]
c
Oooh. I need stroke text soon. Hopefully this lands in the next Alpha.
h
Perfectly aligning two texts on top of each other as in the given design, you need to draw the text letter-by-letter not as a whole layout. Neither
@Composable Text
nor experimental
drawText
will give you the result that you are expecting. The upcoming stroke feature may be of help but I'm not sure. Compose
DrawStyle
can either be Fill or Stroke. This design seems to use white color for stroke, and a dark blue for fill. AFAIK Android platform doesn't support defining different colors for fill and stroke at the same time. You can probably draw stroke'd text on top of fill'ed text with the upcoming API.
Copy code
@Composable
fun FillAndStrokeText(text: String) {
  Box {
    Text(text, style = TextStyle(color = Color.Blue))
    Text(text, style = TextStyle(color = Color.White, drawStyle = Stroke(4f)))
  }
}
c
😍 Do we know when this stroke api is coming
h
soonish 🙂 🤞
Stroke changes are merged to androidx-main meaning that the next release should introduce
DrawStyle
in
TextStyle
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]ain/java/androidx/compose/foundation/demos/text/StrokeDemo.kt