Android TextView Linkify problem with phone numbers and application version number
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 au开发者_运维知识库toLink="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?
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.
Place version to another TextView?
精彩评论