Flex中如何利用getChildAt()和setStyle(),设置TabBar单个Tab样式
2009-06-09 02:01
881 查看
main.mxml
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
import mx.controls.tabBarClasses.Tab;
private function tabBar_creationComplete():void {
var colorArr:Array = ["red", "haloOrange", "yellow", "haloGreen", "haloBlue"];
var color:String;
var tab:Tab;
var idx:uint;
var len:uint = tabBar.dataProvider.length;
for (idx = 0; idx < len; idx++) {
var i:int = idx % colorArr.length;
color = colorArr[i];
tab = Tab(tabBar.getChildAt(idx));
tab.setStyle("fillColors", [color, "white"]);
tab.setStyle("fillAlphas", [1.0, 1.0]);
tab.setStyle("backgroundColor", color);
}
}
private function tabBar_itemClick(evt:ItemClickEvent):void {
viewStack.selectedIndex = evt.index;
}
]]>
</mx:Script>
<mx:Array id="arr">
<mx:Object label="Red" />
<mx:Object label="Orange" />
<mx:Object label="Yellow" />
<mx:Object label="Green" />
<mx:Object label="Blue" />
</mx:Array>
<mx:TabBar id="tabBar"
dataProvider="{arr}"
creationComplete="tabBar_creationComplete();"
itemClick="tabBar_itemClick(event);" />
<mx:ViewStack id="viewStack"
width="{tabBar.width}"
styleName="plain">
<mx:VBox id="redVBox" width="100%" height="100">
<mx:Label text="Red VBox" />
</mx:VBox>
<mx:VBox id="orangeVBox" width="100%" height="100">
<mx:Label text="Orange VBox" />
</mx:VBox>
<mx:VBox id="yellowVBox" width="100%" height="100">
<mx:Label text="Yellow VBox" />
</mx:VBox>
<mx:VBox id="greenVBox" width="100%" height="100">
<mx:Label text="Green VBox" />
</mx:VBox>
<mx:VBox id="blueVBox" width="100%" height="100">
<mx:Label text="Blue VBox" />
</mx:VBox>
</mx:ViewStack>
</mx:Application>
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
import mx.controls.tabBarClasses.Tab;
private function tabBar_creationComplete():void {
var colorArr:Array = ["red", "haloOrange", "yellow", "haloGreen", "haloBlue"];
var color:String;
var tab:Tab;
var idx:uint;
var len:uint = tabBar.dataProvider.length;
for (idx = 0; idx < len; idx++) {
var i:int = idx % colorArr.length;
color = colorArr[i];
tab = Tab(tabBar.getChildAt(idx));
tab.setStyle("fillColors", [color, "white"]);
tab.setStyle("fillAlphas", [1.0, 1.0]);
tab.setStyle("backgroundColor", color);
}
}
private function tabBar_itemClick(evt:ItemClickEvent):void {
viewStack.selectedIndex = evt.index;
}
]]>
</mx:Script>
<mx:Array id="arr">
<mx:Object label="Red" />
<mx:Object label="Orange" />
<mx:Object label="Yellow" />
<mx:Object label="Green" />
<mx:Object label="Blue" />
</mx:Array>
<mx:TabBar id="tabBar"
dataProvider="{arr}"
creationComplete="tabBar_creationComplete();"
itemClick="tabBar_itemClick(event);" />
<mx:ViewStack id="viewStack"
width="{tabBar.width}"
styleName="plain">
<mx:VBox id="redVBox" width="100%" height="100">
<mx:Label text="Red VBox" />
</mx:VBox>
<mx:VBox id="orangeVBox" width="100%" height="100">
<mx:Label text="Orange VBox" />
</mx:VBox>
<mx:VBox id="yellowVBox" width="100%" height="100">
<mx:Label text="Yellow VBox" />
</mx:VBox>
<mx:VBox id="greenVBox" width="100%" height="100">
<mx:Label text="Green VBox" />
</mx:VBox>
<mx:VBox id="blueVBox" width="100%" height="100">
<mx:Label text="Blue VBox" />
</mx:VBox>
</mx:ViewStack>
</mx:Application>
相关文章推荐
- Flex中如何通过horizontalGap样式,设置TabBar控件各个Tab间空格间距
- Flex中如何通过horizontalGap样式,设置TabBar控件各个Tab间空格间距
- Flex中如何通过tabStyleName, tabWidth和textAlign样式,设置TabBar控件内文本对齐方式
- Flex中如何通过tabWidth样式,设置TabBar每个Tab宽度
- Flex的如何设置TabBar中tab的水平位置的例子
- Flex中如何利用getTabAt函数遍历TabNavigator容器的各个Tab,并且通过labelPlacement属性设置标签位置
- Flex中利用getChildAt()和setStyle()设置TabBar单个Tab样式
- Flex中如何利用headerStyleName样式,设置Accordion容器的fillAlphas, fillColors以及selectedFillColors等反显颜色
- Flex中如何利用tabStyleName, firstTabStyleName, lastTabStyleName和selectedTabTextStyleName样式,定制自己的TabNavigator
- Flex中如何利用backgroundImage和backgroundAttachment样式,设置VBox背景图片
- Flex中如何通过paddingTop样式设置TabNavigator控件内容与Tabs间距离的例子
- Flex中如何遍历TabBar控件的各个Tab,并且通过labelPlacement属性设置标签位置
- Flex中如何利用getTabAt函数遍历TabNavigator容器的各个Tab,并且通过labelPlacement属性设置标签位置
- Flex中如何通过paddingTop样式,设置TabNavigator控件内容与Tabs间距离
- Flex中如何利用defaultLeafIcon样式去掉Tree叶子节点图标的例子
- Flex中如何通过dataTipOffset样式设置HSlider控件的数据开销的例子
- Flex的NumericStepper控件中如何通过textAlign样式设置文本对齐方式的例子
- Flex中如何通过borderColor样式设置DateField控件边框颜色的例子
- Flex中如何利用headerSeparatorSkin样式,去掉DataGrid头部分割符
- Flex中如何通过verticalGap样式,设置VBox的各项间间距