简体   繁体   中英

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!

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

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.

您可以在TextView上设置OnClickListener ,重置绘制标志,并调用其invalidate()以便它重新绘制自己。

Setting up AntiAlias helped me to make text look less distored

Kotlin

tv.paintFlags = Paint.ANTI_ALIAS_FLAG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM