之前写过一篇捕获Phoengap的webview事件的方法,主要是在实现了CordovaInterface的Activity中, 在onMessage中根据第一个参数的message name来判断webview的加载事件。不过如果是在Fragment中,一个Activity加载了多个包含了WebView的fragment的话,就无法在onMessage中判断到底是哪个WebView的加载事件。
经过尝试,发现,还是可以使用setWebViewClient的方式来,来重写WebViewClient的对应的onPageStart和onPageFinish等方法来处理加载事件
[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);
p