资源和代号一 [英] Resources and Codename One

查看:20
本文介绍了资源和代号一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Codename One,我想在我的应用程序中插入很多html页面,然后将它们加载到WebView中。我想在资源中插入html文件。如何通过使用GUI构建器数据在资源中插入文件?在WebView中加载html文件的代码是什么?

I am using Codename One and I want to insert a lot of html pages in my app and then load them in a WebView. I want to insert html files in resources. How can I insert files in resources, maybe by using GUI builder data? What is the code to load the html files in WebView?

推荐答案

有几种方法可以做到这一点。如果您可以将每个单独的文件打包为一个文件,则可以使用以下命令:

There are several ways to do this. If you can package every individual file into a single file you can use something like this:


  1. 进行测试。 html 在默认包中

  2. 创建 WebBrowser webBrowser = new WebBrowser(); 并添加到表单中

  3. webBrowser.setUrl( jar:///test.html)

  1. put the test.html in default package
  2. create WebBrowser webBrowser = new WebBrowser(); and add to your form
  3. webBrowser.setUrl("jar:///test.html")

如果您需要复杂的HTML / CSS / JavaScript层次结构,则可以将所有文件放入html根包中( src / html )。
然后使用如下代码从html包中打开HTML文件:

If you need a complex HTML/CSS/JavaScript hierarchy then you can place all your files into the root html package (src/html). Then open an HTML file from within the html package using code like this:

try {
    browserComponent.setURLHierarchy("/htmlFile.html");
} catch(IOException err) {
    ...
}

请注意,该路径是相对于html目录的,并且以 / 开头,但是在HTML文件中,您应该使用
相对(而非绝对)路径。

Notice that the path is relative to the html directory and starts with / but inside the HTML files you should use relative (not absolute) paths.


构建服务器将 tar 该软件包的全部内容并添加
html.tar 文件放入本机包中。当您实际需要资源时,可以在设备上无缝提取
tar ,而只有新应用程序版本的
可用(并非每次启动时都提供)。

The build server will tar the entire content of that package and add an html.tar file into the native package. This tar is seamlessly extracted on the device when you actually need the resources and only with new application versions (not on every launch).

来自

作为补充说明,资源文件确实支持添加任意数据文件,但是层次结构解决方案是一种更好的方法。

As a sidenote the resource files do support adding arbitrary data files but the hierarchies solution is a better approach.

这篇关于资源和代号一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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