将 HTML 文件加载到 WebView [英] Load HTML file into WebView

查看:36
本文介绍了将 HTML 文件加载到 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.

推荐答案

最简单的方法可能是将您的网络资源放入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

更新:assets文件夹通常是以下文件夹:/src/main/assets这可以在 .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:

请参阅文章 Android 中的资产文件夹的放置位置工作室

这篇关于将 HTML 文件加载到 WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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