2015-12-15 37 views
4

我使用Linkify來檢測TextView中的標籤(#)。Android linkify不帶第一個字符

Pattern userMatcher = Pattern.compile("\\[email protected][^:\\s]+"); 
String userViewURL = "https://www.instagram.com/explore/tags/"; 
Linkify.addLinks(tvComment, userMatcher, userViewURL); 

該網址應該以沒有'#'字符的文本結束。

我想用它來搜索的Instagram:

https://www.instagram.com/explore/tags/mytag

但Linkify打開一個網址以 '#' 字符:

https://www.instagram.com/explore/tags/#mytag

如何刪除 '#' 字符從Linkify創建的鏈接。

回答

0

試試這個

Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() { //skip the first character to filter out '@' public String transformUrl(final Matcher match, String url) { return url.substring(1); } };

+0

它的工作原理,謝謝。 –