我在我的應用程序中使用TextView來顯示文本作爲鏈接。Android TextView顯示文本作爲鏈接
我有「See Map」字符串,我想將它顯示爲超鏈接(藍色和下劃線)。
我想這一點:
tvSeeMap.setText(getResources().getString(R.string.see_map));
Linkify.addLinks(tvSeeMap, Linkify.ALL);
,但它不會工作。
我在我的應用程序中使用TextView來顯示文本作爲鏈接。Android TextView顯示文本作爲鏈接
我有「See Map」字符串,我想將它顯示爲超鏈接(藍色和下劃線)。
我想這一點:
tvSeeMap.setText(getResources().getString(R.string.see_map));
Linkify.addLinks(tvSeeMap, Linkify.ALL);
,但它不會工作。
我找到了解決方法
String tempString = new String(getResources().getString(R.string.see_map));
SpannableString content = new SpannableString(tempString);
content.setSpan(new UnderlineSpan(), 0, tempString.length(), 0);
tvSeeMap.setText(content);
tvSeeMap.setTextColor(getResources().getColor(R.color.blue));
就這麼簡單。
鏈接是否有「http://」前綴?如果不是,請嘗試添加它。或者,它可能是之前和之後的它
使用
Linkify.addLinks(tvSeeMap,Linkify.WEB_URLS);
代替
Linkify.addLinks(tvSeeMap, Linkify.ALL);
顯示的超級鏈接或網頁URL作爲鏈接的TextView
'Linkify.ALL'爲0x0F,而'Linkify.WEB_URLS'爲0x01 - 這是您正在處理此錯誤的錯誤嗎? –
yes Linkify.WEB_URLS等於0x01,但不起作用 – Veljko
你想讓它顯示爲超鏈接或顯示並表現爲超鏈接(可點擊)? –
只是要顯示爲超鏈接,我會打開谷歌地圖應用程序點擊。 – Veljko
顯示您想要的示例文本Linkify進程 –