2014-04-28 20 views
0

我知道如何给一个超链接的单词,但现在我需要给一个段内的单词超链接?如何给超链接到段落内的一个词在android

例如我的一段话:

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

我可以做到这一点使用下面的代码,

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); 
+0

为什么你返回www.google.com? – Madhu

+0

非常感谢它的工作。 – Madhu

+0

我很高兴它适合你。 –

0

亲爱Brindha使用这个特定的文字,您可以设置网页或电子邮件或电话或地图或全部按您的要求。

android:autoLink =“web | email | phone | map | all”

+0

感谢您的回答,因为我需要单独给出段落中不同词的链接,所以第一个答案对我有帮助。 – Madhu