Flex中如何利用getChildAt()和setStyle()设置TabBar单个Tab样式的例子


<?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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值