How to make links in a TextView clickable?

后端 未结 30 3860

I have the following TextView defined:



        
30条回答
  •  执笔经年
    2020-11-21 23:50

    After spending some time with this, I have found that:

    • android:autoLink="web" works if you have full links in your HTML. The following will be highlighted in blue and clickable:
    • view.setMovementMethod(LinkMovementMethod.getInstance()); will work with the following (will be highlighted and clickable):

    Note that the third option has a hyperlink, but the description of the link (the part between the tags) itself is not a link. android:autoLink="web" does NOT work with such links.

    • android:autoLink="web" if set in XML will override view.setMovementMethod(LinkMovementMethod.getInstance()); (i.e.; links of the third kind will be highlighted, but not clickable).

    The moral of the story is use view.setMovementMethod(LinkMovementMethod.getInstance()); in your code and make sure you don't have android:autoLink="web" in your XML layout if you want all links to be clickable.

提交回复
热议问题