android - WebView 多个预缓存与 progressBar Android

标签 android caching webview

是否可以使用真正的 ProgressBar 加载多个网页(包括 html、images、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);
            } 
        }

但当我需要几页的总进度时,它只会显示加载一个网页的进度。

我不想自己写一个WebPage grabber,把它放在内部Storage中,因为这会花很多时间,而且可能会导致很多不同的bug和错误。

拜托,你能给我一些想法吗?

最佳答案

is it possible to load multiple WebPages(including html,images,JS,css ) to WebView cache with real ProgressBar ?

不可能。

访问 Android 文档以获取 reference .

关于android - WebView 多个预缓存与 progressBar Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43407070/

相关文章:

android-layout - 在 Android 中 - 如何按特定百分比填充 View 或绘图?

android - 在 View 的背景中画一个半圆

caching - GPU 中的 L1 缓存

android - 以编程方式将文件从缓存目录 move 到 SDCard

java - Android webview输入类型文件

html - 如何在没有 webSockets 的情况下使用 QT WebChannel

java - 从系统应用程序访问/数据文件夹

java - 如何将现有的java项目导入android studio?

php - 设置 HTTP 缓存过期,由 Google PageSpeed 推荐

jquery - 有没有更好的Android webview