2014-03-26 78 views
2

我们怎样才能显示有关我所看到的例子在android系统 链接一些额外的信息,打开链接的浏览器,但不是的情况下我想获取链接信息的android

TextView tv = (TextView) findViewById(R.id.textView1); 
String text = "This is just a test. Click this link here <a href=\"http://www.google.com\">Google</a> to visit google."; 
tv.setMovementMethod(LinkMovementMethod.getInstance()); 
tv.setText(Html.fromHtml(text)); 

我已经尝试了一些像上面,但它是在浏览器中打开代码别的地方我想要的东西像下面的图片

enter image description here

+1

你想要做什么,我不明白?据推测,如果你点击截图中的链接,他们也会在浏览器中打开? – LairdPleng

+1

使用两个TextView第一个包含您的信息文本,第二个包含链接 –

+1

我们如何获得关于链接的信息 –

回答

0

我认为拆分为两个文本的意见是最好的选择。下面是一个类似的线程:

android: html in textview with link clickable

希望这有助于。

+1

我可以使链接点击,但我想要更多inforamtion关于链接显示它在第二个文本视图 –

1

这可以使用URLSpan完成。

TextView tv = (TextView) findViewById(R.id.textView1); 
SpannableString text = new SpannableString("This is just a test. Click this link here to visit google."); 
text.setSpan(new URLSpan("http://www.google.com", 37, 41, 0)); 
tv.setText(text); 

还有几种类型的其他Spans对样式文本非常有用。 37和41是风格文本的开始和结束索引。

另外here是Flavien Laurent对Spans多种用途的优秀博客文章。

+1

我想显示额外的信息。例如:如果该用户发布了YouTube链接,则会显示与该链接或索姆info.PLz帮助相关的某种图片 –

0

您可以使用基本的HTML格式化您的文字TextView。你可以这样做粗体,斜体,链接等。这里是一个示例:

String code = "<p><b>First, </b><br/>" + 
     "Please press the link below.</p>" + 
     "<p><b>Second,</b><br/>" + 
     "Please insert the details of the event." 
     "<a href='http://www.google.com'>click here</a></p>"; 

TextView tv = (TextView) findViewById(R.id.textView1); 
tv.setMovementMethod(LinkMovementMethod.getInstance()); 
tv.setText(Html.fromHtml(code, this, null)); 
tv.setTextSize(16);