是否有XWalkView webview客户端?

时间:2015-10-20 04:54:15

标签: android android-webview crosswalk

我正在尝试在我的Android应用中使用 XWalkView 作为webview替代品。我注意到 XWalkView 对象上没有setWebViewClient方法。问题是我想检查页面何时完成(onPageFinished)以及何时加载资源(onLoadResource)。如何使用 XWalkView

执行此操作

我使用本教程

嵌入了XWalkView

embed crosswalk in android studio

3 个答案:

答案 0 :(得分:16)

Cross Walk API为每个组件引入了自己的名称。不仅WebView已重命名为XWalkView,而且WebViewClient的对应名称为XWalkResourceClientWebChromeClient - XWalkUIClient。因此,您应该使用setWebViewClient方法而不是setResourceClient,而是将XWalkResourceClient实例传递给它。在此对象中,您可以实现一些必需的方法,例如onLoadFinished。有关详细信息,请咨询Cross Walk API documentation

答案 1 :(得分:5)

WebViewClient示例:

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            //Do stuff
        }
    });

同样的事情,但使用XWalkView版本:

xWalkView.setResourceClient(new XWalkResourceClient(xWalkView){
        @Override
        public void onLoadFinished(XWalkView view, String url) {
            super.onLoadFinished(view, url);
            //Do Stuff
        }
    });

答案 2 :(得分:1)

您可以使用ResourceClient。

class ResourceClient extends XWalkResourceClient {
    public ResourceClient(XWalkView xwalkView) {
        super(xwalkView);
    }

    public void onLoadStarted(XWalkView view, String url) {
        mProgress = (ProgressBar) findViewById(R.id.progressBar);
        mProgress.setVisibility(View.VISIBLE);
        super.onLoadStarted(view, url);
        Log.d("INFO", "Load Started:" + url);
    }

    public void onLoadFinished(XWalkView view, String url) {
        super.onLoadFinished(view, url);
        Log.d("INFO", "Load Finished:" + url);
        bottomBar = (BottomBar) findViewById(R.id.bottomBar);
        mProgress = (ProgressBar) findViewById(R.id.progressBar);
        mProgress.setVisibility(View.GONE);
    }

    public void onProgressChanged(XWalkView view, int progressInPercent) {
        super.onProgressChanged(view, progressInPercent);
        Log.d("INFO", "Loading Progress:" + progressInPercent);
        mProgress = (ProgressBar) findViewById(R.id.progressBar);
        mProgress.setProgress(progressInPercent);
    }