Web 视图未在 android 中加载本地 html 文件 [英] web view is not loading local html file in android

查看:29
本文介绍了Web 视图未在 android 中加载本地 html 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 android 中集成 html.我创建了一个 web 视图,但我无法加载本地 html 页面.令人惊讶的是,网络视图正确加载了http:google.com",而不是我的本地 html 文件.我已经尝试了几乎所有可能的 SO 链接.错误信息是无法加载网页"

I am integrating html in android.I have created a web view, But i am not able load local html page. Surprisingly web view is loading 'http:google.com' properly, not my local html file. I have tried almost all possible link of SO. The error message is'Web Page could not be loaded'

WebView view  =  (WebView) findViewById(R.id.webView1);
    view.loadUrl("file:///assets/www/trialhtml.html");![enter image description here][1]

推荐答案

创建您的 HTML 文件并将其放置在 assets 文件夹中,然后您需要将这些行添加到 onCreate 方法中,如下所示:

Create your HTML file and place it in the assets folder, then you need to add these lines to the onCreate method like this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webView = new WebView(this);
    webView.loadUrl("file:///android_asset/test.html");
    setContentView(webView);
}

最终结果如下:

这篇关于Web 视图未在 android 中加载本地 html 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆