TextView超级链接位置标示错误

android_well 发布于 2011/10/28 09:40
阅读 775
收藏 1
<TextView android:id="@+id/link_tv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:autoLink="all" />

public void onCreate(Bundle savedInstanceState) {
    super.oncreate(savedInstanceState);
    setContentView(R.layout.main);   //此布局为上面那个布局
    TextView link_tv = (TextView)findViewById(R.id.link_tv);
    String str = "欢迎访问www.baidu.com.cn的地址信息";   //注意中英文之间不要有空格
    link_tv.setText(str);
}

上面代码运行结果会将“欢迎访问www.baidu.com”标上链接怎么回事???? 

加载中
0
a
android_well
请各位大神指教啊。。。。在线等。。。。。。。
0
鉴客
鉴客

可以用 TextView.setAutoLinkMask(0) 或者指定 android:autoLink=“none”

0
a
android_well
但是我的需求是要将那段正确的网址标上链接啊
a
android_well
@鉴客 : 哦,谢谢,我看看。。
鉴客
鉴客
换一种思路?http://www.oschina.net/question/54100_30605
0
a
android_well

那种方法可以识别网页标签,并将其标上链接,但我的字符串中并不会出现网页标签,那种方法行不通,并且我的TextView里面显示的内容就有两种情况,一种是你的这种思路:含有网页标签的;一种是任意的带有网址的字符串。。。

无鸯
无鸯
给www.baidu.com 前后加多一个空格试试
0
a
android_well
该评论暂时无法显示,详情咨询 QQ 群:点此入群
0
a
android_well
无法再前后加空格。。。
0
JavaGG
JavaGG
加上a标检,好象还有一个textview可以解释一些html的标签的
0
a
android_well
这个问题太奇怪了,为什么英文状态下的链接就会全部标示正确。。。。。。中文就不行
0
a
android_well

问题已经解决,可以通过改变TextView里面的编码然后就可以获取器url了;因为改变成英文状态下编码,通过getUrls()是可以得到url的。然后在其前后加上空格就OK了

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部