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); }
        
    }


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。