将HTML文件加载到WebView中 [英] Load HTML file into WebView
问题描述
我有一个本地html页面以及它所指向的其他一些资源(css文件和Javascript库),我想将它们加载到WebView中.如何实现呢?
I have a local html page along with several other resources pointed by it (css files and Javascript libraries) that I would like to load into a WebView . How could this be achieved ?
也许不是继续前进的最佳方法,但我仍在尝试中.
Perhaps not the best way to procede but I'm still experimenting.
推荐答案
最简单的方法可能是将您的Web资源放入 assets文件夹,然后调用:
The easiest way would probably be to put your web resources into the assets folder then call:
webView.loadUrl("file:///android_asset/filename.html");
有关Java和Webview之间的完整通信请参阅这
For Complete Communication between Java and Webview See This
更新:资产文件夹通常是以下文件夹:
<project>/src/main/assets
可以在您的 <app>.iml
文件中的资产文件夹配置设置中将其更改为:
Update: The assets folder is usually the following folder:
<project>/src/main/assets
This can be changed in the asset folder configuration setting in your <app>.iml
file as:
<option name=ASSETS_FOLDER_RELATIVE_PATH value=/src/main/assets />
请参见文章将资产文件夹放置在Android中的位置Studio
这篇关于将HTML文件加载到WebView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!