原問題來自於CSDN問答頻道,更多解決方案見:http://ask.csdn.net/questions/1995
問題描述:
我在webview中加載了一個 website。當點擊一個鏈接"Full Site",我想開啓手機的默認瀏覽器,如何實現這個功能呢?目前它在web視圖中加載了完整的網站。
解決方案:
你需要在 WebView 對象上添加一個 WebViewClient
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
........
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.mysite.com")) {
//Load the site into the default browser
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
// Load url into the webview
return false;
}
}
如果需要調整 if-statement
語句。