如何给android中段落内的单词提供超链接

时间:2014-04-28 03:13:49

标签: android hyperlink paragraph

我知道如何给word提供超链接,但现在我需要给段落中的单词添加超链接?

例如我的段落:

Lorem Ipsum is simply dummy text of the printing and "typesetting industry". Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

这里我想添加超链接到“排版行业”这个词 , 那可能吗??如果是这样,请帮我解决问题。

2 个答案:

答案 0 :(得分:2)

我可以使用下面的代码

来做到这一点
TextView textView = (TextView)findViewById(R.id.text);
        textView.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.");

        MatchFilter mMatchFilter = new MatchFilter() {
            public final boolean acceptMatch(CharSequence s, int start, int end) {
                return true;
            }
        };
        TransformFilter mTransformFilter = new TransformFilter() {
            public final String transformUrl(final Matcher match, String url) {
                return "www.google.com";
            }
        };

        Pattern mPattern = Pattern.compile("typesetting industry");
        String scheme = "http://";
        Linkify.addLinks(textView, mPattern, scheme, mMatchFilter, mTransformFilter);

答案 1 :(得分:0)

亲爱的Brindha将此用于特定文字,您可以根据自己的要求设置网络或电子邮件或电话或地图或全部。

机器人:自动链接= “网页|电子邮件|电话|地图|所有”