Removing Strikethrough from TextView

2019-01-23 01:57发布

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!

3条回答
唯我独甜
2楼-- · 2019-01-23 02:05

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

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-23 02:19

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

查看更多
Ridiculous、
4楼-- · 2019-01-23 02:20

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

tv.setPaintFlags(0) 

This will remove strike through your text.

查看更多
登录 后发表回答