在android ics中加载url时webview变为空白

时间:2012-05-15 06:46:20

标签: android webview

我正在使用一个在webview中加载url的应用程序,每个东西都工作正常直到andorid api 13级,但是对于andorid ic它表现不同,有些url加载正常但有些导致屏幕闪烁加载时,我有不是具有https的网址这些是简单的http网址。我无法理解为什么会这样,请帮助我。 我的代码是 -

                  progressDialog = ProgressDialog.show(WebViewActivity.this, "",
                   "Loading...");
                  progressDialog.setCancelable(true);

                  webview = (WebView) findViewById(R.id.webview);
                  webview.getSettings().setJavaScriptEnabled(true);
                  webview.setWebViewClient(new MyWebViewClientICS());
                  webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
                  PluginState state = WebSettings.PluginState.ON;
                  webview.getSettings().setPluginState(state);
                  webview.getSettings().setDomStorageEnabled(true);
                  webview.setBackgroundColor(0);
                  webview.getSettings().setSupportZoom(true);

                  webview.setWebChromeClient(new WebChromeClient() {
                  public void onProgressChanged(WebView view, int progress) {
                    if (view.getProgress() == 100) {
                         progressDialog.dismiss();
                            }
                   }
                  webview.loadUrl(url);

                   }

       private class MyWebViewClientICS extends WebViewClient {
       @Override
       public void onReceivedError(WebView view, int errorCode,
            String description, String failingUrl) {
        Log.d("onReceivedError", errorCode + "" + description
                + "failingUrl" + failingUrl);
        Toast.makeText(WebViewActivity.this,
                "Sorry, error in loading page, please try again",
                Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }
}

提前致谢

4 个答案:

答案 0 :(得分:1)

试试这个

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().supportZoom();

答案 1 :(得分:0)

您的设置对我来说很好。您是否尝试过使用标准的“WebViewClient”而不是您自己的“MyWebViewClientICS”?

答案 2 :(得分:0)

试试这个

progressBar = ProgressDialog.show(WebPage.this, "", "Loading...");
url = getIntent().getStringExtra("website");
System.out.println("Url is " + url);
web = (WebView) findViewById(R.id.webView1);

web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setBuiltInZoomControls(false);

web.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Log.i(TAG, "Processing webview url click...");
        view.loadUrl(url);
        return true;
    }

    public void onPageFinished(WebView view, String url) {
        Log.i(TAG, "Finished loading URL: " + url);
        if (progressBar.isShowing()) {
            progressBar.dismiss();
        }
    }
});
web.loadUrl("http://"+url)

答案 3 :(得分:0)

老问题。但这就是我解决问题的原因。

 webView.setBackgroundColor(0x77000000);