样式的使用(五)
【1】global选择符
<fx:Style> global { fontSize:22; textDecoration: underline; } </fx:Style> <s:layout> <s:VerticalLayout/> </s:layout> <s:Button id="myButton" label="Click Me"/> <s:Label id="myLabel" text="This is a Label control."/>
【2】下面的代码可以实现与上面相同的效果,使用styleManager的getStyleDeclaration()方法
<fx:Script> <![CDATA[ private function initApp():void{ styleManager.getStyleDeclaration("global").setStyle("fontSize",22); styleManager.getStyleDeclaration("global").setStyle("textDecoration","underline"); } ]]> </fx:Script> <s:layout> <s:VerticalLayout/> </s:layout> <s:Button id="myButton" label="Click Me"/> <s:Label id="myLabel" text="This is a Label control."/>
【3】styleManager的一个例子
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" xmlns:comps="comps.*" preinitialize="initApp()"> <s:layout> <s:VerticalLayout/> </s:layout> <fx:Script><![CDATA[ import mx.styles.StyleManager; private var mySparkStyle:CSSStyleDeclaration; private function initApp():void{ mySparkStyle=new CSSStyleDeclaration("spark.components.Button"); mySparkStyle.setStyle("fontSize",22); } ]]></fx:Script> <s:Button id="mySparkButton" label="Spark Button"/> <mx:Button id="myHaloButton" label="Halo Button"/> </s:Application>