如何在Android的可点击的锚标记(how to make anchor tag in andro

2019-07-18 15:45发布

this is my code :

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);

The word github appears as a link but nothing happens when I click on the link ...

Answer 1:

你需要调用setMovementMethod :

aboutL1.setMovementMethod(LinkMovementMethod.getInstance());

(你甚至可能不会需要调用Linkify.addLinks因为你使用Html.fromHtml ,但我不能完全记得了)。



Answer 2:

aboutL1.setLinksClickable(true);

XML

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


文章来源: how to make anchor tag in android clickable