diff --git a/app/src/main/assets/sample/界面控件/自定义控件-带颜色按钮.js b/app/src/main/assets/sample/界面控件/自定义控件-带颜色按钮.js new file mode 100644 index 00000000..b4a61181 --- /dev/null +++ b/app/src/main/assets/sample/界面控件/自定义控件-带颜色按钮.js @@ -0,0 +1,50 @@ +"ui"; + +var ColoredButton = (function() { + //继承至ui.Widget + util.extends(ColoredButton, ui.Widget); + + function ColoredButton() { + //调用父类构造函数 + ui.Widget.call(this); + //自定义属性color,定义按钮颜色 + this.defineAttr("color", (view, name, defaultGetter) => { + return this._color; + }, (view, name, value, defaultSetter) => { + this._color = value; + view.attr("backgroundTint", value); + }); + //自定义属性onClick,定义被点击时执行的代码 + this.defineAttr("onClick", (view, name, defaultGetter) => { + return this._onClick; + }, (view, name, value, defaultSetter) => { + this._onClick = value; + }); + } + ColoredButton.prototype.render = function() { + return ( +