setWebViewClient与setWebChromeClient之间有什么区别? [英] What's the difference between setWebViewClient vs. setWebChromeClient?

查看:590
本文介绍了setWebViewClient与setWebChromeClient之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android中setWebViewClientsetWebChromeClient有什么区别?

What's the difference between setWebViewClient vs. setWebChromeClient in Android?

推荐答案

来自使用WebChromeClient可以处理Javascript对话框,图标,标题和进度.看一下这个示例:向WebView添加alert()支持

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

乍看之下,差异太多了 WebViewClient & WebChromeClient .但是,基本上:如果您正在开发不需要太多功能但呈现HTML的WebView,则可以使用WebViewClient.另一方面,如果要(例如)加载要呈现的页面的图标,则应使用WebChromeClient对象并覆盖onReceivedIcon(WebView view, Bitmap icon).

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 a WebViewClient. 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); 

(理论上)您的WebView将实现所有功能(作为android本机浏览器).

And your WebView will (in theory) have all features implemented (as the android native browser).

这篇关于setWebViewClient与setWebChromeClient之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆