ภาษาอังกฤษ
ใช้ HTML เพื่อแสดงผลแบบไดนามิกอินเตอร์เฟสของอินเตอร์เฟส Android
ซึ่งแตกต่างจาก WebView, htmlnative โดยตรงแปลง HTML และ CSS เป็นตัวควบคุมดั้งเดิม ประโยชน์ของการทำเช่นนี้คือ:
<script> API บางตัวถูกรวมเข้าด้วยกันเพื่อสร้าง HNLUA APIวิสัยทัศน์คือการรวม JavaScript ผ่านเครื่องยนต์ V8 เพื่อให้การจำลองของสแต็คเทคโนโลยี H5 ทั้งหมดเสร็จสิ้น
< a > , < p > , < h1 > , < h2 > , < h3 > , < h4 > , < h5 > , < h6 > , < input > , < img > , < div > , < br > , < iframe >
属性:style, onclick(需要再lua脚本中定义onclick事件,后续完善相关文档), id, class, href(for < a > ), src(for < img > ) รองรับแอตทริบิวต์สไตล์อินไลน์และ CSS แบบฝังสำหรับแท็ก <style> ใน <head> ไม่รองรับไฟล์สไตล์ CSS ในรูปแบบลิงค์
ความกว้าง, ความสูง, พื้นหลัง, สีพื้นหลัง, ตำแหน่งพื้นหลัง, ขนาดพื้นหลัง, การขยาย, การขยายด้านซ้าย-ซ้าย, ขวา, ด้านบน, ด้านบน, ด้านล่างด้านล่าง, ระยะขอบ, ขอบด้านบน, ขอบซ้าย, ขอบขวา, ขอบด้านล่าง, ทัศนวิสัย
ขนาดฟอนต์, สี, ความสูงบรรทัด, สไตล์ฟอนต์, ฟอนต์-น้ำหนัก, การจัดเรียงข้อความ, ระยะห่างคำ, ข้อความ, ข้อความที่ไหลออกมา, การเปลี่ยนข้อความ
นอกจากนี้ยังรองรับการได้รับสีและ drawables จาก HTML และใช้ @ เพื่อเริ่มต้นตัวอย่างเช่น:
background : url ( @pic );
color : @colorPrimary ;ประเภทตัวเลือก
p {}
div {}
id选择器
# id1 {}
class选择器
. class1 {}
组
# id1 , # id2 {}
子孙选择器
div p{}
子选择器
div > p{}
全部选择器
* {}
p * {}ผลลัพธ์หลังจากการแสดงผลผ่าน htmlnative:
ดาวน์โหลดวิดีโอ



html:
< html >
< head >
< meta http-equiv =" Content-type " content =" text/html; charset=utf-8 " />
< meta name =" viewport "
content =" user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1 " />
< style >
html{
font-size: 62.5%;
}
body{
margin: 0;
padding: 0;
color: #3f484f;
}
.header{
color:#3f484f;
padding: 2em;
background: #db3541;
-hn-background-color-size: 1.2em 100%;
}
.article{
padding: 3em
}
p{
padding: 5em 0;
font-size: 4em;
line-height: 120%
}
</ style >
< title > article </ title >
</ head >
< body >
< div class =" header " >
< span >头条 | </ span >
< a href =" http://www.sina.com.cn/ " > NewsWebSite </ a >
< h1 >滴滴在硅谷建了研发中心做无人驾驶,还从 Uber 挖了人</ h1 >
< span >来源:新闻网 2017-05-09 </ span >
</ div >
< div class =" article " >
< h2 >这是滴滴在海外的第一个实验室</ h2 >
< p >周四,滴滴正式在美国加州山景城宣布了滴滴美国研究院的成立,一个由数十位工程师和研究人员组成的团队,已经入驻这里,从大数据安全和无人驾驶两个方向展开研究。 </ p >
< div >
< img src =" http://www.abc.com/pic.jpg " alt ="新闻说明" />
< span >滴滴美国研究所</ span >
</ div >
< img src =" http://www.abc.com/pic.jpg " />
< p >美国研究院由滴滴研究院副院长弓峰敏带领。弓峰敏是去年 9 月加入滴滴,担任滴滴信息安全战略副总裁和滴滴研究院副院长,并开始组建美国研究院。加盟滴滴之前,他是安全公司 Palo Alto
Networks 的联合创始人。 </ p >
< p >这一次,滴滴还从Uber挖来了查理·米勒(Charlie Miller)。米勒被誉为全球顶级安全专家,曾是一名黑客,从事苹果越狱和安全研究,在加入 Uber
之前,米勒受雇于苹果。2015 年,米勒完成了对一辆吉普切诺基的远程控制实验。2015 年 9 月,他加入Uber担任汽车安全工程师。 </ p >
< p >在Twitter上,米勒表示他的工作是帮助滴滴研发和使用的自动驾驶系统抵抗来自外部的攻击和威胁。在宣布加入滴滴美国研究院的消息之后,他又发布推文表示实验室正在招人。 </ p >
</ div >
< div >
< img src =" coop/banner.png " />
</ div >
</ body >
</ html > InputStream htmlSource = ...;
// 在需要加载view的时候加载
HNativeEngine . getInstance (). loadView ( mActivity , htmlSource , new
HNativeEngine . OnHNViewLoaded () {
@ Override
public void onViewLoaded ( View v ) {
if ( mActivity != null && ! mActivity . isDestroyed ()) {
mActivity . setContentView ( v );
}
}
@ Override
public void onError ( Exception e ) {
}
@ Override
public void onHead ( HNHead head ) {
}
});HNLUA API เป็นชุดของ API ที่มีความคล่องตัวซึ่งกำหนดไว้ภายใต้กรอบ HTMLNative ผ่าน API นี้คุณสามารถควบคุมอินเทอร์เฟซได้อย่างยืดหยุ่นปรับสไตล์กระโดด URL และเข้าถึงความสามารถของ Android พื้นฐานที่มีการเข้าถึงที่ จำกัด
< html >
< head >
< title > iframe </ title >
< meta name =" nihao " content =" world " />
< style >
#text1{
background:red;
color:green;
margin: 3em 3em;
padding: 2em;
}
button{
color:yellow
}
#parent{
color: red;
}
</ style >
</ head >
< body >
< text id =" text1 " > This is an demo of iframe < br /> nihao
</ text >
< button onclick =" changeText1 " > click me </ button >
< div id =" parent " class =" claz1 claz2 claz3 " > </ div >
</ body >
< script type =" text/lua " >
toast ( "hello world" )
b = false
local vv = document . createView ( "p" , "" )
vv . setAttribute ( "text:helloworld" ) ;
local parent = getElementById ( "parent" )
parent . appendChild ( vv )
console . log ( vv . toString ( ) )
console . log ( vv . getAttribute ( "background" ) ) ;
function changeText1 ( )
local v = getElementById ( "text1" )
console . log ( v . id ( ) )
if ( b ) then
v . setAttribute ( "background:red;color:#fff" )
else
v . setAttribute ( "background:blue;color:red" )
end
b = not ( b )
document . jump ( "http://www.baidu.com" )
end
</ script >
</ html > ในตัวอย่างข้างต้นการใช้ hnluaapi เพิ่ม A <p> แบบไดนามิกและตั้งค่าแอตทริบิวต์ text และในที่สุดก็เพิ่มลงใน <div> ด้วย id=parent ;
นอกจากนี้ยังมีย่อหน้าใน HTML <button onclick="changeText1">click me</button> ซึ่งตั้งค่าเหตุการณ์คลิกสำหรับการควบคุม <button> พฤติกรรมของเหตุการณ์ถูกกำหนดไว้ด้านล่างโดยฟังก์ชั่น changeText1() : เปลี่ยนสีพื้นหลังและสีข้อความแบบไดนามิกผ่านค่าของตัวแปร B; และข้ามไปที่ลิงค์
HNLUAAPI ที่รองรับในปัจจุบัน (ปรับปรุงอย่างต่อเนื่อง):
-- log相关,会以HNConsole的标签出现在Android Logcat中
console . log ( msg )
console . error ( msg )
console . info ( msg )
console . warn ( msg )
--全局操作
document . version () --获取当前HNLuaApi版本号
document . jump ( url ) --跳转至url,具体处理方式,客户端可复写HrefLinkHandler,并在HNativeEngine中注册
doucment . createView ( tag , style ) --以tag方式创建一个标签,并附加上style属性。例如local v = document.createElement("p", "color:red"),该函数返回一个lview对象
--查找view
local lview = document . getElementById ( id ) --通过id查找view
-- lview对象
lview . toString () --转换成stirng
lview . setAttribute ( style ) --设置样式,例如lview.setAttribute("color:red")
lview . id () --获取该标签的id
lview . className () --获取该标签的class,返回为一个LuaTable类型对象
lview . appendChild ( lviewChild ) --往该lview中添加一个子view到末尾
lview . insertBefore ( lviewChild ) --往该lview中添加一个子view到最前面
lview . removeChild ( lviewChild ) --删除view
lview . childNodes () --返回该view的所有子view
lview . getAttribute ( stylename ) --返回某个属性名为stylename的属性值
lview . tagName () --返回该view的tag标签名称
lview . hasChildNode () --检验该lview是否含有子view
lview . setText ( textString ) --设置文本
-- toast
toast ( " helloworld " ) --显示一个toast提示(android only)
--网络操作
local callback = {} --定义一个回调函数
function l . onResponse ( res ) --定义其onResponse方法
toast ( res . body ()) --在其中发起一个toast,并显示response的body中的内容。res有body(), header()及status()方法,可分别访问其HTTP BODY,RESPONSE HEADER及状态码
end
http . get ( " http://www.abc.com " , callback )
http . post ( " http://www.abc.com " , postParams , callback )ลิขสิทธิ์ 2016 Hsllany สงวนลิขสิทธิ์
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.