How to strikethrough Text in android Jetpack Compose?

Viewed 1628

I want to strikethrough a Text in Android Jetpack Compose. I have checked some documentation but I still don't find something that looks to what I want to achieve.

https://developer.android.com/jetpack/compose/text

This is my Text component:

Text("$863",fontSize = 24.sp, modifier = Modifier.width(IntrinsicSize.Min), maxLines = 1)

This is what I want to achieve:

enter image description here

Can any one please help me or give me any idea?

2 Answers

Add style for text

@Composable
fun TextWithLineThroughExample(){
    Text(
        text = "Text with LineThrough",
        style = TextStyle(textDecoration = TextDecoration.LineThrough)
    )
}

enter image description here

I recommend copying the current style with adjusted properties:

@Composable
fun textWithLineThroughExample(){
    Text(
        text = "Text with LineThrough",
        style = LocalTextStyle.current.copy(textDecoration = TextDecoration.LineThrough)
    )
}

This approach keeps all other existing style properties (for example within a ProvideTextStyle block).

Related