Resources and Codename One

喜欢而已 提交于 2019-12-08 07:35:19

问题


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?


回答1:


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. put the test.html in default package
  2. create WebBrowser webBrowser = new WebBrowser(); and add to your form
  3. webBrowser.setUrl("jar:///test.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) {
    ...
}

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.

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).

From the manual.

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



来源:https://stackoverflow.com/questions/35468089/resources-and-codename-one

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!