flex自定義按鈕皮膚示例附圖
更新時(shí)間:2014年04月14日 15:32:47 作者:
這篇文章主要介紹了flex如何自定義按鈕皮膚,需要的朋友可以參考下
先看效果圖:

其中Test.mxml為:
<?xml version="1.0" encoding="utf-8"?>
<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/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- 將非可視元素(例如服務(wù)、值對(duì)象)放在此處 -->
</fx:Declarations>
<mx:HBox horizontalCenter="0" verticalCenter="1">
<s:Button id="rightButton" skinClass="components.RightButtonSkin" />
<s:Button id="cancelButton" skinClass="components.CancelButtonSkin" />
<s:Button id="newStyleButton" skinClass="components.NewStyleButtonSkin"/>
<s:Button id="StyleButton" skinClass="components.StyleButtonSkin"/>
</mx:HBox>
</s:Application>
RightButtonSkin.mxml(確定按鈕皮膚):
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" alpha.disabled=".5">
<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<!-- border and fill -->
<s:Rect id="rect" radiusX="4" radiusY="4" top="0" right="0"
bottom="0" left="0">
<s:fill>
<s:SolidColor color="0xFAFAFA" color.over="0xEEEEEE"
color.down="0xEEEEEE"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke color="0xCCCCCC" weight="1"/>
</s:stroke>
</s:Rect>
<!-- highlight on top -->
<s:Rect radiusX="4" radiusY="4" top="2" right="2" left="2"
height="50%">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF" alpha=".5"/>
<s:GradientEntry color="0xFFFFFF" alpha=".1"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Label text="確定" color="0x131313"
textAlign="center"
fontFamily="宋體"
verticalAlign="middle"
horizontalCenter="0" verticalCenter="1"
left="30" right="30" top="8" bottom="8"
/>
</s:Skin>
NewStyleButtonSkin.mxml(新建按鈕皮膚):
ps:新建按鈕上面那個(gè)icon是畫上去的
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" alpha.disabled=".5">
<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<!-- border and fill -->
<s:Rect id="rect" radiusX="4" radiusY="4" top="0" right="0"
bottom="0" left="0">
<s:fill>
<s:SolidColor color="0xFAFAFA" color.over="0xEEEEEE" color.down="0xEEEEEE"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke color="0xCCCCCC" weight="1"/>
</s:stroke>
</s:Rect>
<!-- highlight on top -->
<s:Rect radiusX="4" radiusY="4" top="2" right="2" left="2"
height="50%">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF" alpha=".5"/>
<s:GradientEntry color="0xFFFFFF" alpha=".1"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Graphic>
<s:BitmapImage source="assets/round_plus2.png" left="8" top="6"/>
</s:Graphic>
<s:Label text="新建樣式" color="0x131313"
fontFamily="宋體"
left="30" right="20" top="8" bottom="8"
/>
</s:Skin>

其中Test.mxml為:
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<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/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- 將非可視元素(例如服務(wù)、值對(duì)象)放在此處 -->
</fx:Declarations>
<mx:HBox horizontalCenter="0" verticalCenter="1">
<s:Button id="rightButton" skinClass="components.RightButtonSkin" />
<s:Button id="cancelButton" skinClass="components.CancelButtonSkin" />
<s:Button id="newStyleButton" skinClass="components.NewStyleButtonSkin"/>
<s:Button id="StyleButton" skinClass="components.StyleButtonSkin"/>
</mx:HBox>
</s:Application>
RightButtonSkin.mxml(確定按鈕皮膚):
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" alpha.disabled=".5">
<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<!-- border and fill -->
<s:Rect id="rect" radiusX="4" radiusY="4" top="0" right="0"
bottom="0" left="0">
<s:fill>
<s:SolidColor color="0xFAFAFA" color.over="0xEEEEEE"
color.down="0xEEEEEE"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke color="0xCCCCCC" weight="1"/>
</s:stroke>
</s:Rect>
<!-- highlight on top -->
<s:Rect radiusX="4" radiusY="4" top="2" right="2" left="2"
height="50%">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF" alpha=".5"/>
<s:GradientEntry color="0xFFFFFF" alpha=".1"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Label text="確定" color="0x131313"
textAlign="center"
fontFamily="宋體"
verticalAlign="middle"
horizontalCenter="0" verticalCenter="1"
left="30" right="30" top="8" bottom="8"
/>
</s:Skin>
NewStyleButtonSkin.mxml(新建按鈕皮膚):
ps:新建按鈕上面那個(gè)icon是畫上去的
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" alpha.disabled=".5">
<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<!-- border and fill -->
<s:Rect id="rect" radiusX="4" radiusY="4" top="0" right="0"
bottom="0" left="0">
<s:fill>
<s:SolidColor color="0xFAFAFA" color.over="0xEEEEEE" color.down="0xEEEEEE"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke color="0xCCCCCC" weight="1"/>
</s:stroke>
</s:Rect>
<!-- highlight on top -->
<s:Rect radiusX="4" radiusY="4" top="2" right="2" left="2"
height="50%">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF" alpha=".5"/>
<s:GradientEntry color="0xFFFFFF" alpha=".1"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Graphic>
<s:BitmapImage source="assets/round_plus2.png" left="8" top="6"/>
</s:Graphic>
<s:Label text="新建樣式" color="0x131313"
fontFamily="宋體"
left="30" right="20" top="8" bottom="8"
/>
</s:Skin>
相關(guān)文章
flex壓縮圖片exif信息(作者/相機(jī))丟失問題解決
使用flex的jpegencoder對(duì)圖片進(jìn)行壓縮的時(shí)候,exif信息會(huì)丟失這一點(diǎn)確實(shí)令人郁悶啊,此問題應(yīng)當(dāng)如何解決呢?經(jīng)研究jpeg的文檔,最終解決這個(gè)問題,曬出來與大家分享希望可以幫助到你們2013-02-02FLEX 獲取DataGrid行號(hào)和列號(hào)示例代碼
獲取DataGrid行號(hào)和列號(hào)在使用過程中還是蠻實(shí)用的,下面為大家詳細(xì)介紹下FLEX是如何做到的,感興趣的朋友可以了解下2013-09-09flex tree自動(dòng)顯示橫向滾動(dòng)條實(shí)現(xiàn)代碼
flex tree自動(dòng)顯示橫向滾動(dòng)條想必有很多的朋友都不會(huì)吧,下面與大家分享下具體的實(shí)現(xiàn)方法,感興趣的你可不要錯(cuò)過了哈2013-05-05Flex調(diào)Javascript打開新窗口示例代碼
Flex通過調(diào)用Javascript打開全屏的新窗口新窗口示例代碼 ,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08Flex讀取txt文件中的內(nèi)容報(bào)錯(cuò)原因分析及解決
這篇文章主要介紹了Flex讀取txt文件中的內(nèi)容報(bào)錯(cuò)原因分析及解決,需要的朋友可以參考下2014-05-05Flex中在Tree綁定數(shù)據(jù)后自動(dòng)展開樹節(jié)點(diǎn)的方法
使用Tree組件在綁定數(shù)據(jù)后自動(dòng)展開所有樹型節(jié)點(diǎn)(不需要用戶再自己點(diǎn)擊展開節(jié)點(diǎn),會(huì)方 便許多),接下來為大家介紹下具體的實(shí)現(xiàn)2014-01-01