跳到主要内容

eui.Theme

   eui

   public class Theme

继承    eui.Theme → egret.EventDispatcheregret.HashObject

皮肤主题。注意:皮肤主题是一次性设置的默认值,并不能运行时切换所有组件默认皮肤。切换单个皮肤您可以自行对Component.skinName赋值来修改。

公共属性

属性

公共方法

方法
Theme(configURL:string,stage:egret.Stage)
创建一个主题实例
getSkinName(client:eui.Component):string
根据主机组件,获取对应的默认皮肤名
mapSkin(hostComponentKey:string,skinName:string):void
为指定的主机组件映射一个默认皮肤

事件

Events
egret.Event.COMPLETE
当主题关联的EXML加载解析完成时派发

属性详细信息

方法详细信息

Theme()

public Theme(configURL:string,stage:egret.Stage)

创建一个主题实例

  • 支持版本:eui 1.0
  • 运行平台:Web,Native
  • 参数
    • configURL:string - 要加载并解析的外部主题配置文件路径。若传入 null,将不进行配置文件加载,之后需要在外部以代码方式手动调用 mapSkin() 方法完成每条默认皮肤名的注册。
    • stage:egret.Stage - 当前舞台引用。若传入null,需要在外部手动调用 egret.registerImplementation("eui.Theme",theme) 来完成主题的注册。

getSkinName()

public getSkinName(client:eui.Component):string

根据主机组件,获取对应的默认皮肤名。查询规则如下:

  • 1.使用client的hostComponentKey作为键查询默认皮肤名。
  • 2.使用client的类名作为键查询默认皮肤名。
  • 3.使用client的父类名作为键查询默认皮肤名。
  • 4.不断重复3直到查询到皮肤名或父类为eui.Component时停止。
    • 支持版本:eui 1.0
    • 运行平台:Web,Native
    • 参数

    mapSkin()

    public mapSkin(hostComponentKey:string,skinName:string):void

    为指定的主机组件映射一个默认皮肤。

    • 支持版本:eui 1.0
    • 运行平台:Web,Native
    • 参数
      • hostComponentKey:string - 主机组件名称,例如:“eui.Button”。
      • skinName:string - 皮肤名称 例如:"app.MyButtonSkin"。

    示例

    **

    * 以下示例使用 ThemeExample 类来显示皮肤主题

    */

    class ThemeExample extends egret.Sprite {

    constructor() {

    super();

    this.once(egret.Event.ADDED_TO_STAGE, this.init, this);

    }

    private progress: eui.ProgressBar;

    private init() {

    var theme = new eui.Theme("resource/green-theme.json", this.stage);

    this.progress = new eui.ProgressBar();

    this.progress.x = 30;

    this.progress.y = 30;

    this.progress.width = 200;

    this.addChild(this.progress);

    this.addEventListener(egret.Event.ENTER_FRAME, this.onEF, this);

    }

    private onEF(): void {

    this.progress.value += 1;

    if (this.progress.value >= 100) this.progress.value = 0;

    }

    }