前几天一qq群里哥们问一个checkbox style的问题,我就觉得反正自己也不会就直接在网上找了一篇帖子,发到这里来了。大家分享一下吧!
-
<?xml version="1.0" encoding="utf-8"?>
-
<mx:Application?name="CheckBox_color_test"
-
? ? ? ? xmlns:mx="http://www.adobe.com/2006/mxml"
-
? ? ? ? layout="vertical"
-
? ? ? ? verticalAlign="middle"
-
? ? ? ? backgroundColor="white">
-
?
-
? ? <mx:Style>
-
? ? ? ? CheckBox {
-
? ? ? ? ? ? fontWeight: bold;
-
? ? ? ? ? ? iconColor: green;
-
? ? ? ? }
-
?
-
? ? ? ? .selectedStyle {
-
? ? ? ? ? ? color: green;
-
? ? ? ? ? ? textRollOverColor: green;
-
? ? ? ? ? ? textSelectedColor: green;
-
? ? ? ? ? ? themeColor: green;
-
? ? ? ? }
-
?
-
? ? ? ? .unselectedStyle {
-
? ? ? ? ? ? color: red;
-
? ? ? ? ? ? textRollOverColor: red;
-
? ? ? ? ? ? textSelectedColor: red;
-
? ? ? ? ? ? themeColor: red;
-
? ? ? ? }
-
? ? </mx:Style>
-
?
-
? ? <mx:Script>
-
? ? ? ? <![CDATA[
-
? ? ? ? ? ? private function checkBox_change(evt:Event):void {
-
? ? ? ? ? ? ? ? var tgt:CheckBox = evt.currentTarget as CheckBox;
-
? ? ? ? ? ? ? ? if (tgt.selected) {
-
? ? ? ? ? ? ? ? ? ? tgt.styleName = "selectedStyle";
-
? ? ? ? ? ? ? ? } else {
-
? ? ? ? ? ? ? ? ? ? tgt.styleName = "unselectedStyle";
-
? ? ? ? ? ? ? ? }
-
? ? ? ? ? ? }
-
? ? ? ? ]]>
-
? ? </mx:Script>
-
?
-
? ? <mx:CheckBox?id="checkBox"
-
? ? ? ? ? ? label="CheckBox"
-
? ? ? ? ? ? selected="false"
-
? ? ? ? ? ? styleName="unselectedStyle"
-
? ? ? ? ? ? change="checkBox_change(event);"?/>
-
?
-
</mx:Application>
其实,这是说的checkbox如果是button或者其他的控件也可以。
<fx:Style>
? ? ? ? ? ? ? ? @namespace s "library://ns.adobe.com/flex/spark";
? ? ? ? ? ? ? ? @namespace mx "library://ns.adobe.com/flex/mx";
? ? ? ? ? ? ? ? .myButton{
? ? ? ? ? ? ? ?? ? icon:Embed(source="logo.gif");
? ? ? ? ? ? ? ? }
? ? ? ? </fx:Style>
- <mx:Button x="449" y="26"??styleName="myButton"/>