2014-03-26 123 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);