Android Application Development may use the WebView component, the use of the process may be exposed to webviewclient and webchromeclient, then what is the difference between the two classes?
webviewclient mainly helps WebView to handle various notifications, request events, such as:
Onloadresource,onpagestart,onpagefinish,onreceiveerror,onreceivedhttpauthrequest and so on.
Webview1.setwebviewclient (New Webviewclient () {public void Onreceivederror (WebView view, int errorCode, String Description, String failingurl) {//handle the Errortoast.maketext (Getapplicationcontext (), "Network connection failed, please connect to network. ", Toast.length_short). Show ();};}); Webview1.getsettings (). Setdefaulttextencodingname ("UTF-8"); Webview1.loadurl ("");
webchromeclient main Auxiliary webview Processing JavaScript dialog box, website icon, website title, loading progress, such as:
Onclosewindow (off WebView), Oncreatewindow (), Onjsalert (WebView on alert invalid, need to customize Webchromeclient processing popup), Onjsprompt, Onjsconfirm,onprogresschanged,onreceivedicon,onreceivedtitle and so on.
For example, you can add a progress bar to make the interface friendlier Webview1.setwebchromeclient (new Webchromeclient () {public void onprogresschanged (WebView view, int progress) { setprogress (progress *), if (progress = =) { imageview1.setvisibility (view.gone); Tv1.setvisibility (view.gone); Pb1.setvisibility (View.gone); Fy1.setvisibility (View.gone); } } } );
It seems that they have a lot of different, actual use, if your webview is only used to deal with some HTML page content, only with webviewclient on the line, if you need more rich processing effect, such as JS, progress bar, etc., it is necessary to use webchromeclient.
More often, you can do this:
WebView webview;webview= (WebView) Findviewbyid (R.id.webview); Webview.setwebchromeclient (new Webchromeclient ()); Webview.setwebviewclient (New Webviewclient ()); Webview.getsettings (). Setjavascriptenabled (True); WEBVIEW.LOADURL ( URL);
Of course, some of the more exciting things you need to add yourself
The difference between webviewclient and webchromeclient