2012-11-26 31 views
-2

我有一個問題,加載本地HTML頁面到webView在android 4之前,我測試了它的android 2.3,它沒問題。我加載這樣的webView.loadUrl頁面(file:///android_asset/drawable/test.html)我讀了很多關於加載本地頁面的bug的信息,但是我沒有解決這個問題。你能解釋一下爲什麼它不加載頁面,並寫下「網頁不可用」。可能是「file:///」或「android_asset」的問題。請給我真正的建議,我可以如何將我的html頁面加載到android 4中的webview。我真的需要。謝謝。在Android 4+加載本地HTML頁面的問題

P.S我確定該文件存在於該文件夾中。

回答

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蜂窩更低的版本比ü應該加載HTML文件的WebView從「文件:/// android_asset/RES /繪製/」如果u有蜂窩,後來不是使用「 file:/// android_res/drawable /「這對我很好。