Android中使用ProgressBar预加载多个WebView页面

3

是否可能将包括HTML、图片、JS和CSS在内的多个网页加载到WebView缓存中,并显示真实进度条?我知道可以用以下方式加载一个页面:

    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
    URL = "https://stackoverflow.com"

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadsImagesAutomatically(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    webView.getSettings().setAppCachePath(appCachePath); 

    if (isNetworkAvailable()) {
        appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    } else {
        Log.e(TAG,"Load page from cache");
        webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
    }

它将使该页面离线加载成为可能,但有没有任何方法创建自定义WebView,在其中我将有机会在数组或列表中加载多个URL,例如

List<String> urls = new ArrayList<>();
urls.add("https://stackoverflow.com");
urls.add("https://google.com");
urls.add("https://facebook.com");
webView.loadURL(ursl);

另外,我需要一个总进度条来加载这些网页。我知道我可以像这样为webView设置WebChromeClient:

 webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                Log.d(TAG,"onProgressChanged" + progress);
            } 
        }

但是它只会展示一个网页的加载进度,而我需要几个页面总体的进度。我不想编写自己的网页抓取程序,并将其存储在内部存储器中,因为这需要很多时间,而且可能会导致许多不同的错误和问题。你能给我一些思路吗?
1个回答

1

是否有可能在WebView缓存中加载多个网页(包括HTML、图像、JS、CSS),并显示真实的进度条?

不可能。

请参阅Android文档reference


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接