2010-01-27 60 views
3

我有一個佈局,我已經設置了android xml佈局。我想在文本視圖中嵌入一個鏈接,這樣如果你點擊鏈接,它會在Android瀏覽器中打開。這是如何完成的。似乎沒有網址瀏覽或任何東西。android查看xml佈局中的url

回答

2

以下是以非明顯但通常希望的方式做到這一點的方法。假設我們想在文本視圖中鏈接單詞blammo。當用戶按下blammo時,瀏覽器打開並將它們發送到google.com

嘗試這樣:

class sampleTransformFilter implements TransformFilter { 
    public String transformUrl(Matcher match, String url) { 
     return "http://google.com"; 
    } 
} 

class sampleMatchFilter implements MatchFilter { 
    public boolean acceptMatch(CharSequence s, int start, int end) { 
     return true; 
    } 
}  

Pattern sampleMatcher = Pattern.compile("blammo");  
String sampleURL = ""; 
Linkify.addLinks(textView, sampleMatcher, sampleURL, new sampleMatchFilter(), new sampleTransformFilter());