【问题标题】:Is there a XWalkView webviewclient?有 XWalkView webviewclient 吗?
【发布时间】:2015-10-20 04:54:15
【问题描述】:

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

我使用本教程嵌入了 XWalkView

embed crosswalk in android studio

【问题讨论】:

    标签: java android android-webview crosswalk xwalkview


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      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
              }
          });
      

      【讨论】:

        【解决方案3】:

        您可以使用 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);
            }
        

        【讨论】:

          猜你喜欢
          • 2011-09-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-01
          • 2012-04-06
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多