0

当用户单击webview. 我想显示一个对话框,询问用户是否想在默认浏览器中查看它,如果他选择是,那么他应该被带到默认浏览器,否则它根本不应该加载链接。
但是,我面临的问题是,我可以在覆盖的方法中run()显示WebViewClient's对话框shouldOverrideUrlLoading()。当用户选择“是”时,我startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(url)));将在默认浏览器中显示它。但是,无论用户选择是/否,它都会显示webview我想要避免的链接。任何建议表示赞赏...TIA

4

2 回答 2

1
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());

private class MyWebViewClient extends WebViewClient {
    @Override
    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

于 2012-11-27T06:47:58.793 回答
0

我通过在 shouldOverrideUrlLoading() 方法中重新加载相同的 URL 解决了这个问题。感谢您的建议

于 2012-11-27T07:02:50.877 回答