0

乳清我写了下面的代码,网址在默认浏览器中打开,为什么它没有加载到我的应用程序中。

setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl("http://www.google.com");
4

2 回答 2

1

尝试WebViewClientWebView:

myWebView.setWebViewClient(new WebViewClient() {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        view.loadUrl(url);
        return true;
    }
});
myWebView.loadUrl("http://www.google.com");
于 2013-01-06T11:23:47.073 回答
1

也许你想要这个解决方案:

WebView webview = findViewById(R.id.webviewLW);
webview = new WebView(this);
webview.getSettings().setLoadsImagesAutomatically(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

webviewLWComplience.setWebViewClient(new WebViewClient() {
        @SuppressWarnings("deprecation")
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(MainActivity.this, description, Toast.LENGTH_SHORT).show();
        }

        @TargetApi(android.os.Build.VERSION_CODES.M)
        @Override
        public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr) {
            // Redirect to deprecated method, so you can use it in all SDK versions
            onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
        }
    });

webviewLWComplience.loadUrl(CONSTANTS.HOST_URL);
setContentView(webviewLWComplience);

不要忘记添加权限:

<uses-permission android:name="android.permission.INTERNET"/>

还要检查这个链接:https ://stackoverflow.com/a/7306176

于 2019-01-10T12:50:43.913 回答