2

我正在一个应用程序中工作,该应用程序具有用于在 webview 中加载的 url,在 andorid api 级别 13 之前,一切都可以正常工作,但是对于 andorid ics,它的行为不同,一些 url 正确加载,但有些在加载时会导致屏幕闪烁,我没有 url https 这些是简单的 http url。我不明白为什么会这样,请帮助我。我的代码是-

                  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

4 回答 4

1

尝试这个

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().supportZoom();
于 2012-05-15T06:54:39.193 回答
0

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

于 2012-05-15T06:51:33.720 回答
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)
于 2012-05-15T07:00:11.440 回答
0

老问题。但这就是为我解决问题的方法。

 webView.setBackgroundColor(0x77000000);
于 2014-07-12T11:02:26.777 回答