SOUI的init.xml的保存着UIDEF,
这个文件的加载代码如下:
IUiDefInfo * pUiDef = SUiDef::getSingleton().CreateUiDefInfo(pResProvider,pszUidef);
SUiDef::getSingleton().SetUiDef(pUiDef,true);
其中SUiDef为SApp中的一个单列对像,它负责解析init.xml。
例如下列文件:
<?xml version="1.0" encoding="utf-8"?>
<UIDEF>
<deffont value="face:微软雅黑,size:15"/>
<string src="values:string" />
<skin src="values:skin"/>
<color src="values:color"/>
<style>
<class name="normalbtn" colorText="@color/text_primary" colorTextPush="@color/text_light" colorTextHover="@color/text_primary" colorTextDisable="@color/text_hint" textMode="0x25" cursor="hand" margin-x="0"/>
<class name="cls_btn_weblink" cursor="hand" colorText="#1e78d5" colorTextHover="#1e78d5" font="italic:1" fontHover="underline:1,italic:1" />
</style>
<template>
</template>
<objattr>
<button class="normalbtn" padding="10,6,10,6" drawFocusRect="false" skin="btn_primary"/>
<imgbtn padding="0,0,0,0"/>
</objattr>
</UIDEF>
其中
deffont为全全局默认字体
string为可引用命名字符串对像,使用形如 @string/xxxx的形式引用
skin为定义的命名皮肤,在需要的地直接使用名称引用
color为可引用命名颜色对像,使用形如 @color/xxxx的形式引用
style为一组样式定义,在控件的class中引用,它的作用是定义一组控件属性,它先于其它属性加载,所以如果在控件定义了和其同名的属性值,那控件定义的属性值就会覆盖style的属性。这功能类似html的css。
template为新增节点,如果你使用较老版本可能不支持,它定义模板控件,方便批量使用。
objattr定义全局控件默认属性(特别注意,objattr的属性值具有遗传特性,比如imgbtn控件继承自button。那这里指定的默认button属性也会传递给imgbtn。但是很显然,有时候不希望这个特性生效,目前还没有解决方案,只能像上面一样,使用同名属性,覆盖父类属性)