I have a layout that I have set up with the android xml layout. I would like to embed a link in a text view so that if you click on th开发者_JS百科e link, it opens in the android browser. how is that done. There does not seem to be a url view or anything.
You should be able to just include the URL in the TextView and then Linkify it. There is also a Tutorial about Linkify and custom links that might help.
Here's how to do this in a non-obvious but commonly desired way. Let's say we want to linkify just the word blammo inside a textview. When the user presses on blammo, a browser opens and sends them to google.com.
Try something like this:
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());
精彩评论