将 html 资源加载到 webview 中的问题 [英] Problems loading html asset into webview
问题描述
我无法将项目资产文件夹中的 html 文件加载到 web 视图中.我查看了数十个教程和解决方案,但似乎没有一个适合我.
I am having difficulty in loading a html file from my project assets folder into a webview. I have looked at dozens of tutorials and solutions but none seem to work for me.
在我项目的资产文件夹中,我有两个简单的 html 文件.index.html 和 faq.html(计划是在我的帮助文档中使用这种结构)
In my project's assets folder I have two simple html files. index.html and faq.html (The plan is to utilise this structure for my help documentation)
我的代码:
WebView wv = (WebView)findViewById(R.id.webview1);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
wv.loadUrl("file:///android_asset/index.html");
网页视图显示以下内容:
The webview displays the following:
Web Page Not Available
The Web Page at file:///android_asset/index.html could not be loaded as:
The requested file was not found. index.html
从我读过的所有内容来看,我在这里应该可以使用,但它没有.
From everything I have read what I have here should work, but it does not.
推荐答案
你的用法是对的,所以如果出现这个问题,你需要仔细检查index.html文件是否存在,你也可以清理项目,并重建它.
your usage is right, so if has this problem, you need check the index.html file existed or not carefully, also you can clean the project, and rebuild it.
这篇关于将 html 资源加载到 webview 中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!