0
A
回答
0
如果你在談論網絡,試試這個:
<p>Your text <a href="https://www.google.com" target="_blank>your link</a> some more text.</p>
在這裏你可以找到關於錨標記的更多信息:https://developer.mozilla.org/en/docs/Web/HTML/Element/a
0
你能在文字之間添加標籤?如果是的話根本就喜歡下面:
<a href="your url">SUV</a> are the best
如果你想linkify文本,而不在文字之間添加標籤,你可以使用正則表達式來做到這一點。
請按照this url爲:
1
需要使用Spannablestring和點擊跨度選項以獲得你需要什麼。
請嘗試以下解決方案。
解決方案1:
XML
<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textSize="24sp"
android:textColor="#234356"
android:padding="5dp"
android:id = "@+id/testview"/>
JAVA
TextView test = (TextView) findViewById(R.id.testview);
SpannableString ss = new SpannableString("SUV is the Best. Offers Avail");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
// open your browser here with the link
Intent i = new Intent(Intent.ACTION_VIEW);
i.setType("*/*");
i.setData(Uri.parse("http://www.google.com")); // your link goes here don't forget to add http://
startActivity(new Intent(Intent.createChooser(i, "Open website using")));
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
// 0 and 3 are the characters start and end where we need to open link on click here SUV
ss.setSpan(clickableSpan, 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
test.setText(ss);
test.setMovementMethod(LinkMovementMethod.getInstance());
test.setHighlightColor(Color.GREEN);
解決方案2:
TextView test = (TextView) findViewById(R.id.testview);
test.setText(Html.fromHtml("<a href=\"http://www.google.com\">SUV</a> <b> is the Best. Offers Avail</b> "));
test.setMovementMethod(LinkMovementMethod.getInstance());
快樂編碼.. !! :)
相關問題
- 1. Windows phone7:點擊按鈕打開網頁?
- 2. 點擊如何打開另一頁?
- 3. 如何在點擊wordpress網站時打開pdf頁面標題
- 4. 如何在InstallShield中點擊按鈕打開網頁?
- 5. 如何通過mac-terminal打開網頁時點擊鏈接?
- 6. C#如何打開一個網頁並點擊一個按鈕
- 7. WebView打開網頁,點擊鏈接顯示「網頁不可用」
- 8. 如何打開一個頁面,點擊模式按鈕打開
- 9. 點擊編輯文字打開菜單
- 10. 如何在網頁中打開網頁?
- 11. 點擊網頁推送通知時打開自定義網址
- 12. 如何打開.NET網頁時在SharePoint網站點擊添加新項按鈕?
- 13. 點擊打開文件
- 14. 如何點擊超鏈接打開打印預覽頁面?
- 15. 如何在php中點擊一些圖片點擊打開新文件點擊
- 16. 如何點擊帶下劃線的文字顯示網頁?
- 17. tableviewcell打開網址點擊迅速
- 18. 在點擊意圖上打開網址
- 19. 點擊ID並打開網址?
- 20. 點擊div打開新鮮的頁面
- 21. xamarin.forms googlemaps infowindow點擊打開新頁面
- 22. 按鈕點擊時打開頁面
- 23. 打開網頁
- 24. 要通過點擊錨標記打開Firefox中的網頁
- 25. Python 2.7 Tkinter打開網頁瀏覽器點擊
- 26. 用JavaScript模擬點擊打開網頁上的窗口
- 27. 打開網頁並點擊Android中的按鈕
- 28. install4j - 點擊超鏈接,網頁瀏覽器不打開
- 29. Ctrl鍵點擊無法打開鏈接的網頁
- 30. 點擊按鈕後在UIWebView中打開網頁