模板引擎
https://github.com/tomj74/chunk-templates
官方文档
https://www.x5software.com/chunk/wiki/#How_to_get_Chunk
添加依赖
1 | implementation 'com.x5dev:chunk-templates:3.5.0' |
添加引用
1 | import com.x5.template.Chunk |
模板文件要放在src/main/assets/themes
文件夹下
假如文件为ztex.chtml
注意文件必须以.chtml
作为后缀
使用方法
1 | private fun getChunk(): Chunk { |
模板中这样取值
1 | {$content} |
这样chunk.toString()
获取到的就是把变量已经塞进模板后的字符串了。
页面中引用JS/CSS
在src/main/assets/katex
文件夹下的文件katex.min.css
在页面中可以通过以下方式引用:
1 | <link rel="stylesheet" type="text/css" href="file:///android_asset/katex/katex.min.css"> |
Webview加载网页文本
1 | loadDataWithBaseURL(null, htmlText, "text/html", "utf-8", "about:blank") |
高度和内部高度自适应
直接添加android:layout_height="wrap_content"
即可。
本身就支持不用通过网页加载完事件再把高度传出来。