我想使用网页来显示我的内容,因为这将利用 android 中内置的缩放和滚动功能。我知道我希望将网页放在 sdcard 上以允许无法访问 Internet,但我不知道如何从 res/raw/ 文件夹中调用它。我能得到一些帮助吗?谢谢
4 回答
有一种情况是我们不能使用assets
文件夹。如果我们想从库项目中获得 WebView 加载资源怎么办。assets
不支持文件夹,但支持res/raw
。
据我所知,从 API 8 开始,以下工作正常:
webView.loadUrl("file:///android_res/raw/webPage.html");
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");
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");
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");