-1
我有一个web视图,加载链接。我收到了一些Url,它们也包含其他网址。我想知道是否有可能,当用户点击webview内的网址时,该网址将被加载到另一个浏览器中,而不是在webview内?Webview内部链接
我有一个web视图,加载链接。我收到了一些Url,它们也包含其他网址。我想知道是否有可能,当用户点击webview内的网址时,该网址将被加载到另一个浏览器中,而不是在webview内?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
你可以分享你码? – albertoqa