通过headerStyleName 为accordion的标题自定义样式:

代码:

1  mxml文件:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"   
  3.                xmlns:s="library://ns.adobe.com/flex/spark"   
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:skins="skins.*"> 
  5.     <fx:Declarations> 
  6.         <!-- 将非可视元素(例如服务、值对象)放在此处 --> 
  7.     </fx:Declarations> 
  8.     <fx:Style> 
  9.         @namespace s "library://ns.adobe.com/flex/spark";  
  10.         @namespace mx "library://ns.adobe.com/flex/mx";  
  11.         .accorhead{  
  12.             /* skinClass:ClassReference("skins.AccordionHeaderSkin") */  
  13.             skin:ClassReference("skins.AccordionHeaderSkin");  
  14.         }  
  15.     </fx:Style> 
  16.     <mx:VBox width="100%" height="100%" verticalAlign="middle" horizontalAlign="center"> 
  17.         <mx:Accordion headerStyleName="accorhead" paddingTop="-1"> 
  18.             <mx:VBox label="11111"  width="200" height="200" verticalAlign="middle" horizontalAlign="center" backgroundColor="#F6F8FC">   
  19.                 <s:Button label="111111"/> 
  20.             </mx:VBox> 
  21.             <mx:VBox label="22222" width="200" height="200" verticalAlign="middle" horizontalAlign="center" backgroundColor="#F6F8FC"> 
  22.                 <s:Button label="222222"/> 
  23.             </mx:VBox> 
  24.             <mx:VBox label="33333" width="200" height="200" verticalAlign="middle" horizontalAlign="center" backgroundColor="#F6F8FC"> 
  25.                 <s:Button label="222222"/> 
  26.             </mx:VBox> 
  27.         </mx:Accordion> 
  28.           
  29.         <s:Button label="hahahaha" skinClass="skins.ButtonSkin"/> 
  30.           
  31.     </mx:VBox> 
  32. </s:Application> 

其中包括了css样式,只有使用headerStyleName,为其指定一个css类 如上 .accorhead

然后在css类中给属性skin赋值(skinclass没有效果),指向一个自定义的皮肤文件

2  皮肤文件如下:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2.     <s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"   
  3.                                xmlns:s="library://ns.adobe.com/flex/spark"   
  4.                                xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:spark="mx.skins.spark.*" width="400" height="300"> 
  5.         <fx:Declarations> 
  6.             <!-- 将非可视元素(例如服务、值对象)放在此处 --> 
  7.         </fx:Declarations> 
  8.         <s:states>    
  9.              <s:State name="up" />    
  10.                <s:State name="over" />    
  11.              <s:State name="down" />    
  12.                <s:State name="disabled" />    
  13.               <s:State name="selectedUp" />    
  14.            <s:State name="selectedOver" />    
  15.             <s:State name="selectedDown" />    
  16.               <s:State name="selectedDisabled" />    
  17.              </s:states>    
  18.       
  19.         <s:Rect height="25" left="1" right="1" top="1" bottom="1" id="fill"> 
  20.             <s:fill> 
  21.                 <s:LinearGradient rotation="90"> 
  22.                     <s:GradientEntry color="#DCE6EF" color.selectedUp="#F6F8FC"/> 
  23.                     <s:GradientEntry color="#A2BBD5" color.selectedUp="#F6F8FC"/> 
  24.                     <s:GradientEntry color="#99B4D1" color.selectedUp="#F6F8FC"/> 
  25.                 </s:LinearGradient> 
  26.             </s:fill> 
  27.         </s:Rect> 
  28.         <s:Rect left="0" right="0" top="0" bottom="0" id="border"> 
  29.             <s:stroke> 
  30.                 <s:SolidColorStroke color="#99B4D1" color.selectedUp="#000000"/> 
  31.             </s:stroke> 
  32.         </s:Rect> 
  33.     </s:SparkButtonSkin> 

3 效果如下图所示:

 

flex 学习笔记 accordion(二)_flex学习 

flex 学习笔记 accordion(二)_flex学习_02 

学习ING。。