我正在创建一个 Flex 主题并定义默认组件外观。所有按钮都应具有默认外观。可以使用 styleName 将特殊样式应用于按钮,它为按钮皮肤定义一组颜色。
我创建了一个 Spark Button 皮肤,如下所示:
<!-- ButtonSkin.mxml -->
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" minWidth="21" minHeight="24" alpha.disabled="0.5">
<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.Button")]
[Style(name="backgroundGradient", states="up, over, down", format="Array", inherit="yes")]
]]>
</fx:Metadata>
<fx:Script>
<![CDATA[
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
var backgroundGradient:Array = getStyle("backgroundGradient");
topGradientEntry.color = backgroundGradient[0];
bottomGradientEntry.color = backgroundGradient[1];
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
]]>
</fx:Script>
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<!-- shapes using topGradientEntry.color and bottomGradientEntry.color -->
</s:Skin>
像这样设置主css文件:
/** default.css **/
s|Button {
skinClass: ClassReference('mytheme.skins.ButtonSkin');
fontWeight: bold;
}
skins|ButtonSkin {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-primary:up {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-primary:over {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-primary:down {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-inverted:up {
backgroundGradient: 0xFFFFFF, 0x000000;
}
s|Button.btn-inverted:over {
backgroundGradient: 0xFFFFFF, 0x000000;
}
s|Button.btn-inverted:down {
backgroundGradient: 0xFFFFFF, 0x000000;
}
应用程序会像这样设置按钮的样式:
<!-- Main.mxml -->
<s:Button label="Default" x="10" y="10" width="75" height="26"/>
<s:Button label="Button" x="110" y="10" width="75" height="26" styleName="btn-success"/>
<s:Button label="Primary" x="210" y="10" width="75" height="26" styleName="btn-primary"/>
但是我在所有情况下都收到错误“不支持'backgroundGradient'的CSS值”。