0

我已经为 textview 设置了 android:autoLink="all" 但是当我尝试将一些锚链接合并到该文本视图中时,锚链接不会显示为链接。任何人都可以帮忙。

4

2 回答 2

1

我想你正在寻找这个http://xjaphx.wordpress.com/2011/09/12/auto-link-for-textview/

 textview.setText("any data");
 Linkify.addLinks(textview, Linkify.ALL);

http://developer.android.com/reference/android/text/util/Linkify.html

更新:

String urlink = "http://www.google.com";
String link = "<a href="+urlink+ ">link</a>"; 

TextView tv = (TextView) findViewById(R.id.textview);

tv.setText(link);
Linkify.addLinks(tv, Linkify.ALL);

最新的:

String googleLink = "http://www.google.com ";
String clickLink = "click here";
Spannable mSpannableString= new SpannableString(googleLink+clickLink);
mSpannableString.setSpan(new URLSpan("http://www.google.com"), 0, googleLink.length(), 0); 
mSpannableString.setSpan(new URLSpan("http://www.example.com"), googleLink.length(), clickLink.length(), 0); 

TextView tv = (TextView) findViewById(R.id.textview);
tv.setMovementMethod(LinkMovementMethod.getInstance());  
tv.setText(mSpannableString)
于 2012-06-05T09:12:09.800 回答
0

对于使用下面的代码片段Linkify的文本TextView

TextView tv = (TextView)v.findViewById(R.id.text4);
Linkify.addLinks(tv, Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);

编辑:

TextView tv= (TextView)findViewById(R.id.textview1);
    String urlink = "google.com";
    String link = "<a href=\""+urlink + "\">link</a>";
    tv.setText(Html.fromHtml(link));
    Linkify.addLinks(tv, Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);
于 2012-06-05T09:15:47.410 回答