creating a strikethrough text? creating a strikethrough text? android android

creating a strikethrough text?


Paint.STRIKE_THRU_TEXT_FLAG

TextView someTextView = (TextView) findViewById(R.id.some_text_view);someTextView.setText(someString);someTextView.setPaintFlags(someTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

For painting text, there are several bit flags for doing things like bold, italics, and yes strikethrough. So to enable the strikethrough, you need to flip the bit that corresponds to this flag. The easiest way to do this is to use a bitwise-or on the current flags and a constant that corresponds to a set of flags with only the strikethrough flag enabled.

Edit from Comment by Ε Г И І И О :

For any one wanting to remove this flag, this is how:

someTextView.setPaintFlags(someTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));


It is really easy if you are using strings:

<string name="line"> Not crossed <strike> crossed </strike> </string>

And then just:

<TextView         ...         android:text="@string/line" />


If you are using Kotlin:

your_text_view.apply {    paintFlags = paintFlags or Paint.STRIKE_THRU_TEXT_FLAG    text = "Striked thru text"}