-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