Text link

Linkify

TextView textView = (TextView)findViewById(R.id.myTextView);
Linkify.addLinks(textView, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES);

 

Use linkify in xml

 

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/linkify_me"
android:autoLink="phone|email"
/>

 

Creating Custom Link Strings

 

int flags = Pattern.CASE_INSENSITIVE;
Pattern p = Pattern.compile("//bquake[0-9]*//b", flags);
Linkify.addLinks(myTextView, p,
"content://com.paad.earthquake/earthquakes/");

 

Using the Match Filter

Linkify.addLinks(myTextView, pattern, prefixWith,
new MyMatchFilter(), new MyTransformFilter());

 

class MyMatchFilter implements MatchFilter {
public boolean acceptMatch(CharSequence s, int start, int end) {
return (start == 0 || s.charAt(start-1) != ‘!’);
}
}

 

class MyTransformFilter implements TransformFilter {
public String transformUrl(Matcher match, String url)
return url.toLowerCase();
}
}

阅读更多
个人分类: Android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭