Previously wrote a method to capture Phoengap's WebView event, mainly in the implementation of cordovainterface activity, in OnMessage according to the first parameter of the message name to determine the WebView load event. However, in fragment, if an activity loads multiple fragment containing webview, it is not possible to determine in OnMessage which WebView's Load event.
After trying, find, or can use setwebviewclient way, to rewrite the corresponding webviewclient Onpagestart and Onpagefinish methods to handle the Load event
[Java]
Cordovawebview WebView = (cordovawebview) Findviewbyid (R.id.webview);
Cordovawebview WebView = (cordovawebview) Findviewbyid (R.id.webview); [Java] View plaincopyprint? Cordovainterface cordovainterface = (cordovainterface) context;
Cordovawebviewclient cordovawebviewclient = new Cordovawebviewclient (Cordovainterface, WebView) {
@Override
public void onpagestarted (WebView view, String URL, Bitmap favicon) {
Logutil.debug ("onpagestarted" + URL);
super.onpagestarted (view, URL, favicon);
Progressbar.setvisibility (view.visible);
}
@Override
public void onpagefinished (WebView view, String URL) {
Logutil.debug ("onpagefinished" + URL);
super.onpagefinished (view, URL);
Progressbar.setvisibility (View.gone);
}
@Override
public void Onreceivederror (WebView view, int errorCode, string description, String failingurl) {
Logutil.debug ("onreceivederror" + URL);
Super.onreceivederror (view, ErrorCode, description, Failingurl);
Progressbar.setvisibility (View.gone);
Errorview.setvisibility (view.visible);
}
};
Webview.setwebviewclient (cordovawebviewclient);
Webview.loadurl (URL);
Cordovainterface cordovainterface = (cordovainterface) context;
Cordovawebviewclient cordovawebviewclient = new Cordovawebviewclient (Cordovainterface, WebView) {
@Override
public void onpagestarted (WebView view, String URL, Bitmap favicon) {
Logutil.debug (" onpagestarted "+ URL);
super.onpagestarted (view, URL, favicon);
Progressbar.setvisibility (view.visible);
}
@Override
public void onpagefinished (WebView view, String URL) {
Logutil.debug ("onpagefinished" + URL);
super.onpagefinished (view, URL);
Progressbar.setvisibility (View.gone);
}
@Override
public void Onreceivederror (WebView view, int errorCode, string description, String failingurl) {
Logutil.debug ("onreceivederror" + URL);
Super.onreceivederror (view, ErrorCode, description, Failingurl);
Progressbar.setvisibility (View.gone);
Errorview.setvisibility (view.visible);
}
};
Webview.setwebviewclient (cordovawebviewclient);
Webview.loadurl (URL);
Listen for webview monitoring in Android is loading complete