Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Strikethrough from TextView

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!

like image 637
edwoollard Avatar asked Sep 18 '13 20:09

edwoollard


People also ask

How to remove Strikethrough in android TextView?

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

How do you strikethrough text in TextView?

If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint. STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text. TextView textView = (TextView) findViewById(R.


2 Answers

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

like image 181
edwoollard Avatar answered Sep 30 '22 08:09

edwoollard


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.

like image 43
Ronak Mehta Avatar answered Sep 30 '22 09:09

Ronak Mehta