setwebviewclient()和setwebchromeclient()
2015-01-14 14:52
197 查看
整理一些在网上搜集的webview的两个方法的区别:setwebviewclient()和setwebchromeclient(),以备查阅。
原文网址:http://www.android100.org/html/201306/26/3290.html
setWebChromeClient主要处理解析,渲染网页等浏览器做的事情
WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等
onCloseWindow(关闭WebView)
onCreateWindow()
onJsAlert (WebView上alert是弹不出来东西的,需要定制你的WebChromeClient处理弹出)
onJsPrompt
onJsConfirm
onProgressChanged
onReceivedIcon
onReceivedTitle
比如可以添加进度条,使得界面更友好
WebViewClient就是帮助WebView处理各种通知、请求事件的,具体来说包括:
onLoadResource
onPageStart
onPageFinish
onReceiveError
onReceivedHttpAuthRequest
例如:
} public boolean shouldOverrideUrlLoading(WebView
view, String url) { view.loadUrl(url); return true;
} }); //设置字符集编码
原文网址:http://www.android100.org/html/201306/26/3290.html
setWebChromeClient主要处理解析,渲染网页等浏览器做的事情
WebChromeClient是辅助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); } } } );
WebViewClient就是帮助WebView处理各种通知、请求事件的,具体来说包括:
onLoadResource
onPageStart
onPageFinish
onReceiveError
onReceivedHttpAuthRequest
例如:
webview1.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // Handle the error Toast.makeText(getApplicationContext(), "网络连接失败 ,请连接网络。", Toast.LENGTH_SHORT).show(); } public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); //设置字符集编码 webview1.getSettings().setDefaultTextEncodingName("UTF-8"); webview1.loadUrl("http://www.android100.org/"); }
</pre><div class="cnblogs_code"><pre><span style="font-family: 'Microsoft YaHei', 微软雅黑, 'Microsoft JhengHei', 华文细黑, STHeiti, MingLiu;"></span>
使用WebChromeClient 可以操作Javascript dialogs(js脚本对话框), favicons(添加收藏的标志), titles(标题), 和 progress(进度条). 简单的说,如果除了加载HTML的话,只需要用WebViewClient即可,但是在进行兼容互联网上附加javascript的页面的时候和调用javascript对话框的时候,或者功能较为复杂的内嵌操作的时候,建议使用WebChromeClient 。} http://bbs.52studying.com/thread-434-1-1.html
} public boolean shouldOverrideUrlLoading(WebView
view, String url) { view.loadUrl(url); return true;
} }); //设置字符集编码
相关文章推荐
- android setWebChromeClient和setWebViewClient的使用区别
- webview的两个方法:setWebChromeClient和setWebClient
- android webView setWebChromeClient and setWebClient
- WebView中的JavaScript代码使用 setWebChromeClient
- SetWebViewClient和 SetWebChromeClient的区别
- webview的两个方法:setWebChromeClient和setWebClient
- webview中setWebChromeClient和setWebClient区别
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- WebViewClient与WebChromeClient的区别
- WebViewClient与WebChromeClient的区别
- android.webkit.WebView/WebViewClient/WebChromeClient
- 使用WebView, WebChromeClient和WebViewClient加载网页
- WebViewClient与WebChromeClient的区别
- WebViewClient 与 WebChromeClient
- WebView,WebViewClient,WebChromeClient区别(转载)
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- WebViewClient与WebChromeClient的区别
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- WebChromeClient 与WebViewClient的区别
- Android中使用WebView, WebChromeClient和WebViewClient加载网页