Android的Edittext-结算跨度 [英] Android Edittext- Clearing Spans
问题描述
我想获得一个EditText通过调用 EditText.getText()来清除它的跨度。clearSpans()
。不过,如果我调用这个方法,在开始的EditText出现异常,与换行显示为框和任何跨度然后我设置完全错误的地点。
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.
我的问题是:如何明确跨度往返的EditText? (如果没有调用的setText() - 文本可能是数千行代码和过慢的重绘它都经常)
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)
非常感谢!
推荐答案
有同样的问题。通过删除我加入的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:
toRemoveSpans = et.getSpans(0, et.getText().length(), ForegroundColorSpan.class);
for (int i = 0; i < toRemoveSpans.length; i++)
et.removeSpan(toRemoveSpans[i]);
这篇关于Android的Edittext-结算跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!