如何创建TextView的链接,使其无需Android的下划线 [英] how to create textview link without underscore in android

查看:269
本文介绍了如何创建TextView的链接,使其无需Android的下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来到了这个情况有线,我的code是如下

i came into this wired situation, my code is as follow

LinearLayout ll = new LinearLayout(this);
TextView tv = new TextView(this);
ll.addView(tv);
tv.setText(Html.fromHtml("<a STYLE=\"text-decoration:none;\" href=\"" 
        + StringEscapeUtils.escapeJava(elem.getChildText("newsLink")) + "\">" 
                + StringEscapeUtils.escapeJava(elem.getChildText("Title")) + "</a>"));
tv.setTextColor(Color.BLACK);

风格=文字修饰:无 tv.setTextColor(color.black)这两个没有工作,链接仍然在蓝色下划线,为什么他们没有工作的任何提示?谢谢!

but the style="text-decoration:none" and tv.setTextColor(color.black)both not working, the link is still in blue with underscore, any hints on why they're not working? Thanks!

推荐答案

你可以试试这个。如

String content = "your <a href='http://some.url'>html</a> content";

下面是去除超链接下划线一个简洁的方式:

Here is a concise way to remove underlines from hyperlinks:

Spannable s = (Spannable) Html.fromHtml(content);
for (URLSpan u: s.getSpans(0, s.length(), URLSpan.class)) {
    s.setSpan(new UnderlineSpan() {
        public void updateDrawState(TextPaint tp) {
            tp.setUnderlineText(false);
        }
    }, s.getSpanStart(u), s.getSpanEnd(u), 0);
}
tv.setText(s);

这篇关于如何创建TextView的链接,使其无需Android的下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆