Removing strikethrough text from a TextView

I use this line below to set strikethrough in my TextView:

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

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

Thanks in advance!

+32
android android-listview textview flags android-textview strikethrough
Sep 18 '13 at 20:31 on
source share
5 answers

I ended up finding this online:

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

This successfully deletes the strikethrough, and so I called it in my OnListItemClick method after doing a check in the database, which I did to check if the item was already broken (purchased in my case).

+78
Sep 18 '13 at 20:44 on
source share

Another way is to simply set setPaintFlags to zero.

 tv.setPaintFlags(0) 

NOTE: this will remove the punch through your text.

+14
Sep 25 '14 at 6:33
source share

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

+3
Sep 18 '13 at 20:39
source share

Just use Html.fromHtml (String.format (Locale.US, "<del> ₹% s </del>", "your text is here")); // remove the space in the <del> tag

0
Jan 29 '19 at 12:12
source share

The AntiAlias ​​setting helped me make the text less distorted

Kotlin

 tv.paintFlags = Paint.ANTI_ALIAS_FLAG 
0
Mar 12 '19 at 6:19 06:19
source share



All Articles