webView 加载进度条,webView返回键重写机制

1、图片延时加载

brower = (WebView) this.findViewById(R.id.brower);
settings = brower.getSettings();
settings.setJavaScriptEnabled(true);
//阻塞图片下载
settings.setBlockNetworkImage(true);

private class Client extends WebViewClient
    {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon)
        {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url)
        {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            view.getSettings().setBlockNetworkImage(false);
        }
        
        

    }

2、加载进度条显示

private class ChromeView extends WebChromeClient
    {
        @Override
        public void onProgressChanged(WebView view, int newProgress)
        {
            // TODO Auto-generated method stub
            super.onProgressChanged(view, newProgress);
            if (newProgress == 100) {
                progressbar.setVisibility(GONE);
            } else {
                if (progressbar.getVisibility() == GONE)
                    progressbar.setVisibility(VISIBLE);
                progressbar.setProgress(newProgress);
            }
        }

3、返回键重写

public boolean onKeyDown(int keyCode, KeyEvent event) {  if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {   mWebView.goBack();// 返回前一个页面   return true;  }  return super.onKeyDown(keyCode, event); }
        
    }


你可能感兴趣的:(chrome,webView)