SetWebViewClient和 SetWebChromeClient的区别
来源:互联网 发布:淘宝卖家服务软件 编辑:程序博客网 时间:2024/05/14 15:09
参考;http://blog.csdn.net/dufangyu1990/article/details/39693181
Using WebChromeClient allows you to handle Javascript dialogs, favicons, titles, and the progress. Take a look of this example: Adding alert() support to a WebView
At first glance, there are too many differences WebViewClient & WebChromeClient. But, basically: if you are developing a WebView that won’t require too many features but rendering HTML, you can just use aWebViewClient. On the other hand, if you want to (for instance) load the favicon of the page you are rendering, you should use a WebChromeClient object and override the onReceivedIcon(WebView view, Bitmap icon).
Most of the times, if you don’t want to worry about those things… you can just do this:
webView= (WebView) findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
And your WebView will (in theory) have all features implemented (as the android native browser).
说的很清楚了setWebChromeClient比setWebViewClient功能强大一些,
setWebClient帮助WebView处理各种通知、请求事件
onLoadResource
onPageStart
onPageFinish
onReceiveError
onReceivedHttpAuthRequest
如果你不需要太多的功能而仅仅是渲染一个HTML网页,只需要用setWebViewClient就可以了,但是如果要处理比较复杂的事务,就考虑用后者
2.setWebChromeClient辅助WebView处理JavaScript的对话框,网站图标,网站title,加载进度等
onCloseWindow(关闭WebView)
onCreateWindow()
onJsAlert (WebView上alert是弹不出来东西的,需要定制你的WebChromeClient处理弹出)
onJsPrompt
onJsConfirm
onProgressChanged
onReceivedIcon
onReceivedTitle
例如添加进度条:
webview1.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { setProgress(progress * 100); if(progress == 100){ imageView1.setVisibility(View.GONE); tv1.setVisibility(View.GONE); pb1.setVisibility(View.GONE); fy1.setVisibility(View.GONE); } } } );
另外如果你怕顾虑太多,可以这样使用
webView= (WebView) findViewById(R.id.webview); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(url);
但是我感觉这样子好奇怪
- SetWebViewClient和 SetWebChromeClient的区别
- android setWebChromeClient和setWebViewClient的使用区别
- setwebviewclient()和setwebchromeclient()
- webview中setWebChromeClient和setWebClient区别
- webview中setWebChromeClient和setWebClient区别
- setWebClient与setWebChromeClient之间的区别
- webview的两个方法:setWebChromeClient和setWebClient
- webview的两个方法:setWebChromeClient和setWebClient
- webview有两个方法:setWebChromeClient和setWebClient
- android之webview的.setWebViewClient(new WebViewClient()几个方法重写
- android webView setWebChromeClient and setWebClient
- 和和的区别
- & 和 &&、|和||的区别:
- &和&&、|和||的区别
- &&和&,||和|的区别
- &和&&、|和||的区别
- &和&&、|和||的区别
- ../和./和/的区别
- SqlServer数据库的存储过程以及事务处理
- Network Representation 网络节点嵌入
- 最小编辑代价(动态规划)
- struts2开发简单实例
- HashSet重写hashCode,equals方法去除重名元素
- SetWebViewClient和 SetWebChromeClient的区别
- HDOJ 1087最大递增子序列和
- 我的Android之旅(八)---ViewPage+Fragment+ListView
- Problem A: 小火山的跳子游戏zzulioj
- HDU-2044-一只小蜜蜂
- 云计算的一些概念
- 简单git仓库搭建
- 【java开发系列】—— struts2简单入门示例
- leetcode Reverse Nodes in k-Group