Android: Clickable TextView with Linkified links

2019-05-25 05:35发布

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

2条回答
仙女界的扛把子
2楼-- · 2019-05-25 06:13

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

查看更多
SAY GOODBYE
3楼-- · 2019-05-25 06:31

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.

查看更多
登录 后发表回答