-2

我在 android 4 中将本地 html 页面加载到 webView 时遇到问题。之前,我针对 android 2.3 对其进行了测试,结果还可以。我像这样加载页面 webView.loadUrl(file:///android_asset/drawable/test.html) 我阅读了很多关于加载本地页面错误的信息,但我还没有解决这个问题。你能解释一下为什么它不加载页面并写下“网页不可用”。可能是“file:///”或“android_asset”的问题。请给我真正的建议,如何将我的 html 页面加载到 android 4 中的 webview。我真的需要。谢谢你。

PS我确定该文件存在于该文件夹中。

4

1 回答 1

0

我解决了我的问题。我用了:

private final int boundaryApiValue = 10; 

/**Function set root directory for current api version.*/ 

    private void setRootPathForCurrentVersionOfAndroid() {
        if (Build.VERSION.SDK_INT >= boundaryApiValue)
            rootPath = "file:///android_res/drawable/";
        else {
            rootPath = "file:///android_asset/res/drawable/";
        }
    }

如果你的版本低于 Android HoneyComb,你应该从“file:///android_asset/res/drawable/”加载 webview 的 html 文件,如果你有 HoneyComb 并且比使用“file:///android_res/drawable/”更晚这对我来说很好。

于 2012-11-28T11:43:27.430 回答