Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to strikethrough Text in android Jetpack Compose?

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?

like image 429
Luis Aguilar Avatar asked Sep 04 '25 17:09

Luis Aguilar


2 Answers

Add style for text

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

enter image description here

like image 51
Tippu Fisal Sheriff Avatar answered Sep 07 '25 14:09

Tippu Fisal Sheriff


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).

like image 23
SapuSeven Avatar answered Sep 07 '25 15:09

SapuSeven