Android Edittext-清除跨度
我试图通过调用 EditText.getText().clearSpans() 来清除其跨度。但是,如果我调用此方法,EditText 就会开始表现得很奇怪,换行符显示为框,然后我设置的任何跨度都位于完全错误的位置。
所以我的问题是:如何清除 EditText 中的跨度? (如果不调用 setText() - 文本可能有数千行长,并且频繁重绘它太慢)
非常感谢!
I am trying to get an EditText to clear its spans by calling EditText.getText().clearSpans()
. However, if I call this method, the EditText starts to behave strangely, with line feeds appearing as boxes and any spans I then set being in completely the wrong place.
So my question is: How do I clear spans from and EditText? (Without calling setText()- the text may be thousands of lines long and its too slow to redraw it all frequently)
Thanks very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有同样的问题。通过仅删除我添加到 EditText 的跨度类型解决了这个问题。我猜clearSpans 删除的内容超出了应有的范围。我对我使用的每种类型的跨度做了类似的事情:
Had the same problem. Solved it by removing only the types of spans that I added to the EditText. I guess clearSpans removes more than it should. I did something like this for each type of span I used:
根据您添加的跨度类型,您可能需要包含的不仅仅是 ForegroundColorSpan。上述方法是简单的替换,并且很容易指定要删除的跨度。
Depending on type of spans you have added you may have to include more than just ForegroundColorSpan. The above method is a simple drop in replacement and it easy to specify what spans to remove.
最好的答案是“s”是您想要显示的字符串而不是跨度,或者它可以是空字符串。
代码位于Kotlin
the best answer would be this which "s" is the string that you want to show instead of spans or it can be empty String.
the code is in Kotlin