如何知道哪个单词有下划线?
我可以使用以下方法在编辑文本框中的单词下划线:
contentText.getEditableText().setSpan(new UnderlineSpan(), position, endLen, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
在我给单词划下划线后,是否有任何方法可以让我知道哪个单词被下划线?这是因为我需要知道有多少个单词以及下划线的单词是什么。预先感谢您回答我的问题。
I can underlined a word in edittext box using this method:
contentText.getEditableText().setSpan(new UnderlineSpan(), position, endLen, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
After i underlined the word, is there any methods that can let me know which word is underlined?This is because I need to know how many words and what is the word that had underlined. Thanks in advance for answering my question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
getSpanEnd(对象标签)和 getSpanStart(Object tag) 来确定跨度的开始和结束。唯一的事情是您需要引用原始 UnderlineSpan 对象。
我将这样做。
You can use
getSpanEnd(Object tag) and getSpanStart(Object tag) to determine the start and end of the span. The only thing is u need to have reference to original UnderlineSpan Object.
Here is how I would do it.
你已经知道下划线是什么词了。你只是强调了它。使用
position
和endLen
检索带下划线的文本。虽然您可以稍后调用
getSpans()
来检索UnderlineSpan
,但UnderlineSpan
不包含有关其位置的信息。You already know what word is underlined. You just underlined it. Use
position
andendLen
to retrieve the text that you underlined.While you can call
getSpans()
later on to retrieve theUnderlineSpan
, theUnderlineSpan
does not contain information about its position.