44

I'm using this line below in order to set a strikethrough on my TextView:

tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

However later on in the Fragment, if they click the TextView again, I would like the strikethrough to be removed. What line of code can I use to simply make the TextView display the text in the normal format again?

Thanks in advance!

edwoollard
  • 12,245
  • 6
  • 43
  • 74

4 Answers4

94

I ended up finding this online:

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

This successfully removes the strikethrough and therefore I called this in my OnListItemClick method after carrying out a check in the database I made to see if the item had already been striked through (purchased in my case).

edwoollard
  • 12,245
  • 6
  • 43
  • 74
22

Another way is to simply set value of setPaintFlags to Zero.

tv.setPaintFlags(0) 

NOTE:

This will remove strike through your text and other Typeface design, You are free to use in case it doesn't applied to your view.

Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
  • 11
    this will also remove the other paint features like the Typeface design off the text and make it look like a skeleton without flesh on it! – Naaz May 05 '15 at 16:36
3

You can set an OnClickListener on the TextView, reset the paint flags, and call its invalidate() so it redraws itself.

Emmanuel
  • 13,083
  • 4
  • 39
  • 53
  • I like your idea and I'm sure I could get that method to work, however I found a simpler answer online. Thanks anyway. – edwoollard Sep 18 '13 at 22:24
2

Setting up AntiAlias helped me to make text look less distored

Kotlin

tv.paintFlags = Paint.ANTI_ALIAS_FLAG
pratham kesarkar
  • 3,770
  • 3
  • 19
  • 29