开发者

Inline hyperlinks in Android TextView

开发者_Go百科

How can I create inline hyperlinks in a TextView while having different values for the link URL and link text?


You can do this by using the SpannableString stuff that Android has. Specifically, you can attach a URLSpan to whatever text you want and set the URL to an arbitrary URL. Just create a SpannableString (or SpannableStringBuilder if you're composing several strings), attach a URLSpan using setSpan and then put that in the TextView. Note that you have to call setMovementMethod to an instance of LinkMovementMethod otherwise the clicks won't work. Oh, and don't try and have an onClick handler on the TextView as well, you're going to get very frustrated if you try and do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜