1

我想使用网页来显示我的内容,因为这将利用 android 中内置的缩放和滚动功能。我知道我希望将网页放在 sdcard 上以允许无法访问 Internet,但我不知道如何从 res/raw/ 文件夹中调用它。我能得到一些帮助吗?谢谢

4

4 回答 4

6

有一种情况是我们不能使用assets文件夹。如果我们想从库项目中获得 WebView 加载资源怎么办。assets不支持文件夹,但支持res/raw

据我所知,从 API 8 开始,以下工作正常:

webView.loadUrl("file:///android_res/raw/webPage.html");
于 2013-05-24T08:42:22.037 回答
2

Put the webpage in the assets folder instead. Then when you want to load it, use this line of code:

webView.loadUrl("file:///android_asset/myWebPage.html");
于 2012-04-20T04:14:19.237 回答
0

First get String from Drawable Folder, see following link to get contetnts of a file from raw folder:

http://www.41post.com/3985/programming/android-loading-files-from-the-assets-and-raw-folders

and Then you can use WebView's loadData method to load html contents in webview.

Other method is to load html file by:

mWebView.loadUrl("file:///android_asset/myfile.html"); 
于 2012-04-20T04:13:30.420 回答
0

You can set an html file from the assets folder like this

WebView wv;  
wv = (WebView) findViewById(R.id.webView1);  
wv.loadUrl("file:///android_asset/aboutcertified.html");  
于 2012-04-20T04:14:34.230 回答