2

I'm using a TextField or BasicTextField in compose and setting strikethrough span on the text using:

SpanStyle(textDecoration = TextDecoration.LineThrough)

It renders strikethrough on the text as expected. However, when I place the cursor on it, the strikethrough disappears and the text is underlined instead. Underlining is the default behavior I think whenever the cursor is placed on the text so I think that's fine.

enter image description here

enter image description here

But how do I get strikethrough to show when the cursor is positioned on the text?

This doesn't happen on view-based EditText or AppCompatEditText.

Vikram Gupta
  • 6,496
  • 5
  • 34
  • 47

2 Answers2

0

Try setting paint flags for editText

editText.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG

remove set

editText.paintFlags = Paint.CURSOR_AFTER
Ranu Dhurandhar
  • 93
  • 1
  • 10
0

You can try something like this,

SpanStyle(textDecoration = TextDecoration.LineThrough, 
              underline = TextDecoration(
                  color = Color.Red,
                  thickness = 1.dp,
                  width = TextDecoration.Width.Intrinsic
              )
    )

This will apply a red underline with a thickness of 1dp when the cursor is placed on the text. You can adjust the values to fit your desired styling.

Alternatively, you can also disable the underline altogether by setting the underline to TextDecoration.None.

scss

SpanStyle(textDecoration = TextDecoration.LineThrough, 
          underline = TextDecoration.None
)

This will prevent any underline from appearing when the cursor is placed on the text.