Flex Gumbo中如何创建渐变背景颜色NumericStepper的例子
By Minidxer | August 24, 2009
接下来的Flex Gumbo中如何利用LinearGradient对象和skinClass样式,创建渐变背景颜色NumericStepper。
下面是main.mxml:
- <?xml version="1.0" encoding="utf-8"?>
- <s:Application name="Spark_NumericStepper_skinClass_test"
- xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/halo">
- <s:NumericStepper id="numericStepper"
- skinClass="skins.CustomNumericStepperSkin"
- horizontalCenter="0"
- verticalCenter="0" />
- </s:Application>
下面是Skin类Skins/CustomNumericStepperSkin.mxml的代码:
- <?xml version="1.0" encoding="utf-8"?>
- <s:SparkSkin name="CustomNumericStepperSkin"
- xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- minHeight="24"
- alpha.disabled="0.5">
- <s:states>
- <s:State name="normal" />
- <s:State name="disabled" />
- </s:states>
- <fx:Metadata>
- <![CDATA[
- [HostComponent("spark.components.NumericStepper")]
- ]]>
- </fx:Metadata>
- <fx:Script>
- /* Define the skin elements that should not be colorized.
- For numeric stepper, the skin itself is colorized but the individual parts are not. */
- static private const exclusions:Array = ["textInput", "decrementButton", "incrementButton"];
- override public function get colorizeExclusions():Array {return exclusions;}
- </fx:Script>
- <s:Button id="incrementButton" right="0" top="0" height="50%"
- skinClass="spark.skins.default.SpinnerIncrButtonSkin" />
- <s:Button id="decrementButton" right="0" bottom="0" height="50%"
- skinClass="spark.skins.default.SpinnerDecrButtonSkin" />
- <s:TextInput id="textInput" left="0" top="0" right="18" bottom="0"
- skinClass="skins.CustomNumericStepperTextInputSkin" />
- </s:SparkSkin>
还需要自定义的CustomNumericStepperTextInputSkin.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- alpha.disabled="0.5">
- <s:states>
- <s:State name="normal"/>
- <s:State name="disabled"/>
- </s:states>
- <fx:Metadata>
- <![CDATA[
- [HostComponent("spark.components.TextInput")]
- ]]>
- </fx:Metadata>
- <fx:Script>
- /* Define the skin elements that should not be colorized. */
- static private const exclusions:Array = ["background", "textView"];
- override public function get colorizeExclusions():Array {return exclusions;}
- /* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
- static private const contentFill:Array = [];
- override public function get contentItems():Array {return contentFill};
- </fx:Script>
- <!-- border -->
- <s:Rect left="0" right="0" top="0" bottom="0">
- <s:stroke>
- <s:LinearGradientStroke rotation="90" weight="1">
- <s:GradientEntry color="0x000000" alpha="0.5525" />
- <s:GradientEntry color="0x000000" alpha="0.6375" />
- </s:LinearGradientStroke>
- </s:stroke>
- </s:Rect>
- <!-- fill -->
- <s:Rect id="background" left="1" right="1" top="1" bottom="1">
- <s:fill>
- <s:LinearGradient id="bgFill" rotation="90">
- <s:entries>
- <s:GradientEntry color="haloBlue" />
- <s:GradientEntry color="haloGreen" />
- </s:entries>
- </s:LinearGradient>
- </s:fill>
- </s:Rect>
- <!-- shadow -->
- <s:Rect left="1" top="1" right="1" height="1">
- <s:fill>
- <s:SolidColor color="0x000000" alpha="0.12" />
- </s:fill>
- </s:Rect>
- <!-- text -->
- <s:RichEditableText id="textView"
- left="1" right="1" top="1" bottom="1"
- paddingLeft="3" paddingTop="5"
- paddingRight="6" paddingBottom="3"/>
- </s:SparkSkin>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Gumbo, NumericStepper |
No Comments » |
Tags: background, Gumbo, lineargradient, skinClass