Android: Clickable TextView with Linkified links

时间秒杀一切 提交于 2019-12-08 02:09:59

问题


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.



来源:https://stackoverflow.com/questions/4251745/android-clickable-textview-with-linkified-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!