3

我有一个大文本视图,我正在使用 SpannableStringBuilder 进行样式设置。我希望能够将自定义单击事件处理程序分配给某些文本范围。例如,如果我单击一个上标字符,我希望它弹出一个 toast,其中包含有关上标引用的一些信息。到目前为止,我发现 linkify 有助于使诸如电子邮件和电话号码之类的正则表达式类型的事物启动适当的活动。我想要做的是定义一个跨度及其样式并为其分配一个点击处理程序。我还没有找到支持这种功能的内置任何东西,所以我要求任何对如何做到这一点有新想法的人。谢谢。

4

2 回答 2

1

The only thing I can think of is for you to take a look at the Android source code for the Linkify class and see how that does it.

于 2009-12-26T02:39:58.500 回答
1

看看扩展 ClickableSpan。 http://developer.android.com/reference/android/text/style/ClickableSpan.html

URLSpan 是用于 Linkify 的跨度,是 ClickableSpan 的示例实现。 http://developer.android.com/reference/android/text/style/URLSpan.html

于 2013-04-23T18:36:11.070 回答