如何在android可点击中制作锚标签

时间:2013-01-24 13:38:56

标签: android html anchor

这是我的代码:

TextView aboutL1 = (TextView) findViewById(R.id.aboutL2);
    aboutL1.setText(Html.fromHtml("This app is open source.<br>The source code is hosted on <a href=\"http://herp.com/derp\">Github</a> "));
    Linkify.addLinks(aboutL1, Linkify.ALL);

单词github显示为链接,但点击链接时没有任何反应...

2 个答案:

答案 0 :(得分:10)

您需要致电setMovementMethod

aboutL1.setMovementMethod(LinkMovementMethod.getInstance());

(您可能甚至不需要拨打Linkify.addLinks因为您使用了Html.fromHtml,但我无法完全记住。)

答案 1 :(得分:1)

aboutL1.setLinksClickable(true);
XML 中的

应为

<TextView
    android:id="@+id/aboutL2"
    android:autoLink="web"
    android:linksClickable="true"
/>