我尝试在我的 android 项目中使用名为 Chunk Templates(类似于 velocity)的模板引擎(获取地址为 https://code.google.com/p/chunk-templates/)。在使用它时,我需要访问我的 Assets 文件夹中的模板文件:
Theme t = new Theme("path to file"); //path getAssets()..? file:///....?
Chunk c = t.makeChunk("template"); //template.chtml
c....
“template.chtml”位于我的 eclipse 文件夹“assets\themes\template.chtml”中 在我的设备上运行它时,模板引擎提示找不到模板。
我必须使用什么路径?
您好, 哈姆兹蒂
最佳答案
好的,我给作者写了一封电子邮件,解决方案仍未发布,将在未来的发行版中添加。我得到了一个实验版本,其中的代码如下所示:
AndroidThemeLoader loader = new AndroidThemeLoader(getBaseContext());
Theme theme = new Theme(loader);
Chunk chunk = theme.makeChunk("test#subtest");
chunk.set("name", "Dennis");
String html = chunk.toString();
String mime = "text/html";
String encoding = "utf-8";
WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
String baseURL = null;
myWebView.loadDataWithBaseURL(baseURL, html, mime, encoding, null);
谢谢大家对我的帮助!
关于java - 从 Android 中的 Assets 传递路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20211471/