Flex4 新增的spark组件中,已经没有background属性了,取而代之的style和theme了。
例如
InputText.setStyle("contentBackgroundColor", 0xFF0000);
把textinput的背景设置为红色。
还可以通过 css来设置这些组件的style,这个contentBackgroundColor只会对spark组件的TextInput生效。
<fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; s|TextInput { contentBackgroundColor: #FFFF99; } </fx:Style>
多个css样式的选择,在控件的styleName中加上css的名字即可,按照出现的先后次序来应用。
<fx:Style> .myFontStyle { fontSize: 22; } .myOtherFontStyle { color: #9933FF; } </fx> <s:Button id="myButton" styleName="myFontStyle myOtherFontStyle" label="Click Me"/>
可以根据空间的id来选择样式,
s|Button#Button3 { color:blue;}
<s:Button id="Button3" label="Click"/>
全局应用css样式,flex中专门有一个叫global的名字,这个名字下的样式会被应用到所有控件,除非控件自身明确指出。也可以通过
styleManager来设置全局样式。
<fx:Style> global { fontSize:22; textDecoration: underline; } </fx:Style> styleManager.getStyleDeclaration("global").setStyle("fontSize", 22); styleManager.getStyleDeclaration("global").setStyle("textDecoration", "underline"); styleManager.getStyleDeclaration("spark.components.Button").setStyle("fontSize",15); styleManager.getStyleDeclaration("spark.components.Button").setStyle("color",0x9933FF);
参考:
http://www.dremsus.com/index.php/tag/getstyle/
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fee.html