网页视图内部链接
Webview internal links
我有一个网页视图,可以加载链接。我得到了一些 Url ,其中还包含其他 Url。我想知道是否有可能,当用户在 webview 中单击 url 时,那个 url 会被加载到另一个浏览器中,而不是在 webview 中?
使用以下代码,如果 link 在您的网站中,它将在 webview 中打开,否则它将打开一个新的浏览器:
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}});
更多信息:http://developer.android.com/guide/webapps/webview.html#AddingWebView
我有一个网页视图,可以加载链接。我得到了一些 Url ,其中还包含其他 Url。我想知道是否有可能,当用户在 webview 中单击 url 时,那个 url 会被加载到另一个浏览器中,而不是在 webview 中?
使用以下代码,如果 link 在您的网站中,它将在 webview 中打开,否则它将打开一个新的浏览器:
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}});
更多信息:http://developer.android.com/guide/webapps/webview.html#AddingWebView