我想知道是否以及如何将Web链接添加到TextView小部件。在我的应用程序中,我显示了一些文字并在文字旁边显示了一张图像。我想在文本中插入可点击的互联网链接。这可能吗?将网页链接添加到TextView小部件
8
A
回答
10
您只需要设置android:autolink属性。
<TextView
android:autoLink="web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://www.google.com" />
+0
Thx,它完美的工作! –
+0
非常直接,容易添加。谢谢! +1 – Darrell
0
这是我如何做它通过代码
private void setAsLink(TextView view, String url){
Pattern pattern = Pattern.compile(url);
Linkify.addLinks(view, pattern, "http://");
view.setText(Html.fromHtml("<a href='http://"+url+"'>http://"+url+"</a>"));
}
0
如果您的网站链接是你是显示在TextView的文本中的不同:
TextView的在你的布局文件:
<TextView
android:id="@+id/textview_with_hidden_clickable_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/string_with_text_and_link"/>
你的字符串资源文件:
<string name="string_with_text_and_link">
<a href="http://any_web_site">The text in your TextView</a>
</string>
而在你的Java类:
((TextView)findViewById(R.id.textview_with_hidden_clickable_link))
.setMovementMethod(LinkMovementMethod.getInstance());
注:
http://
在字符串资源是必要的。
相关问题
- 1. 将“小部件”添加到网站
- 2. 添加链接从网页到灯箱
- 3. 添加Facebook的链接到网页
- 4. 将内部超链接添加到pdf
- 5. 将innerhtml添加到顶部链接
- 6. jQuery将_blank添加到外部链接
- 7. 将外部网络小部件添加到面板
- 8. 将查看次数添加到网站上的外部链接
- 9. 如何将本地网页链接添加到WSS门户?
- 10. 将JavaScript动作添加到网页上的所有链接
- 11. 如何将外部营销视频的链接添加到网站主页?
- 12. 如何添加链接到Switch小部件的文本?
- 13. 将链接添加到链接
- 14. 将链接添加到javascript
- 15. 将链接添加到iframe
- 16. 将小部件添加到ScrollArea
- 17. 将小部件添加到Google日历
- 18. 将小部件添加到Qsqlquerymodel
- 19. 将定制小部件添加到QStackedWidget
- 20. 将小部件添加到主屏幕
- 21. 将CSS添加到GWT小部件
- 22. 将类添加到WordPress小部件ul
- 23. Appcelerator - 将小部件添加到tableviewrow
- 24. 将标签添加到小部件
- 25. 将小部件添加到活动
- 26. 将javascript添加到超链接控件
- 27. 将链接添加到电子邮件
- 28. 添加网页链接CakePHP中
- 29. 如何灯箱添加网页链接
- 30. WordPress将默认小部件添加到小部件区域
http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable – VicVu