Android TextView Linkify problem with phone numbers and application version number

梦想的初衷 提交于 2019-12-11 04:47:30

问题


I have a problem with TextView and autoLink feature.

I have an about screen in my application with some information like support phone number, email address, website URL and application version in form like 01.01.01

After setting autoLink="all" on the textView, all values are linked fine - except that version number 01.01.01 is linked as the phone number as well.

Is there some way to exclude this text fragment from linkifing?


回答1:


Place version to another TextView?




回答2:


Just don't use autoLink, linkify text from your code. It's quite easy using Linkify class.

private static final String phoneRegex="123\.456\.789";//you can just place your support phone here
private static final Pattern phoneMatcher = Pattern.compile(phoneRegex);

public static void linkify(TextView text){
    Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES);
    Linkify.addLinks(text, Linkify.WEB_URLS);
    Linkify.addLinks(text, phoneMatcher, "tel:");
}

You don't need to modify url and email expression. But you should specify your own expression for phone. And it doesn't need to be an expression that matches all phones. It just needs to match your specific support phone.



来源:https://stackoverflow.com/questions/2882161/android-textview-linkify-problem-with-phone-numbers-and-application-version-numb

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