Android 中的超链接 [英] Hyperlink in Android

查看:53
本文介绍了Android 中的超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题:如何在普通文本的文本块中放置超链接?我有一些文本,在文本中我提到了一个 URL,我希望这个 URL 使用不同的颜色、带下划线和可点击.

I have a question: How can I place a hyperlink WITHIN a text-block of normal text? I have some text and in the text I mention a URL and I want this URL to be in a different color, underlined and click-able.

我知道 android 中的超链接可以用Linkify"放置..我已经提到了 android docs 页面

I know hyperlinks in android can be placed with "Linkify".. and i have referred android docs page

考虑与我想在android中显示的android docs"相同的上述段落.....

推荐答案

@Fedor....我发现提供来自 的链接API 演示 .

@Fedor.... i have found to give links from API Demos .

这种方法最终用于在段落文本之间提供链接.

this approach is finally be used for giving link in between text of paragraph.

     SpannableString ss = new SpannableString("text4: Click here 
                                                  to dial the phone.");

    ss.setSpan(new StyleSpan(Typeface.ITALIC), 0, 6,
           Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
           Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    TextView t4 = (TextView) findViewById(R.id.TextView01);
    t4.setText(ss);
    t4.setMovementMethod(LinkMovementMethod.getInstance());

这篇关于Android 中的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆