Set Link Clickable in Java-Android

旧街凉风 提交于 2020-02-27 06:21:47

问题


I am designing an App, where there is TextView, and based on some check condition, I want to make links / phone numbers in the TextView clickable in Java side. Can I do this, I don't want to make it clickable by default which is done by setting in xml file

 android:autoLink="all" 

What I already tried: Create regular TextView and don't set autoLink="all",

     TextView myView = 
                (TextView)view.findViewById(R.id.thisIstheTextView);
       myView .setLinksClickable(true);

also tried :

     myView .setMovementMethod(LinkMovementMethod.getInstance());

None of the above Java code works, I don't want a predesigned xml TextView with autoLink enabled, I want to change the TextView behavior in Java code based on if () conditions. There is no error in my code, but I am not able to achieve what I want. Can you please share your knowledge. Thank you.


回答1:


Use setAutoLinkMask (int mask).

The possible values that can be combined for mask are those defined for the Linkify class.




回答2:


 Linkify.addLinks(myView, Linkify.ALL);

Fixed the issue.



来源:https://stackoverflow.com/questions/9725931/set-link-clickable-in-java-android

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