Android: Clickable TextView with Linkified links

2019-05-25 05:50发布

问题:

I have a TextView in my layout which has an attribute "clickable=true" set in XML. This is to allow it behave like a button with both text and icon. Now, I add to that TextView HTML text via call HTML.fromHtml(), and apply Linkify.addLinks after that.

The problem is: in such configuration, links are not clickable. Is there any suggestion, how to allow user click on links, other from creating custom TextView-based class?

Thanks

回答1:

try add an attribute "android:autoLink="web"" to the textview



回答2:

Also, I have struggled hours against the TextView before realizing that

<resources>
  <string name="mytext">Going to <a href="http://www.google.fr/">Google</a> is linkifed but NOT clickable</string>
</resources>

But this is:

<resources>
  <string name="mytext">Go to http://www.google.fr/ is linkified and clickable</string>
</resources>

In both cases, the link is recognized and styled accordingly.