简体   繁体   English

从 TextView 中删除删除线

[英]Removing Strikethrough from TextView

I'm using this line below in order to set a strikethrough on my TextView:我正在使用下面的这一行在我的 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.但是稍后在 Fragment 中,如果他们再次单击 TextView,我希望删除删除线。 What line of code can I use to simply make the TextView display the text in the normal format again?我可以使用哪一行代码来简单地使 TextView 再次以正常格式显示文本?

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).这成功地删除了删除线,因此我在检查我所做的数据库以查看该项目是否已经被删除(在我的情况下购买)后,在我的OnListItemClick方法中调用了它。

Another way is to simply set value of setPaintFlags to Zero.另一种方法是简单地将setPaintFlags值设置为零。

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设置 AntiAlias 帮助我使文本看起来不那么失真

Kotlin科特林

tv.paintFlags = Paint.ANTI_ALIAS_FLAG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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