How to make links in a TextView clickable?

后端 未结 30 3337

I have the following TextView defined:



        
30条回答
  •  后悔当初
    2020-11-21 23:59

    If you want to add HTML-like link, all you need to do is:

    • add a resource HTML-like string:

       Google
      
    • add your view to the layout with NO link-specific configuration at all:

       `
      
    • add appropriate MovementMethod programmatically to your TextView:

       mLink = (TextView) findViewById(R.id.link);
       if (mLink != null) {
         mLink.setMovementMethod(LinkMovementMethod.getInstance());
       }
      

    That's it! And yes, having options like "autoLink" and "linksClickable" working on explicit links only (not wrapped into html tags) is very misleading to me too...

提交回复
热议问题