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

main.mxml

  1. <?xml version="1.0"?>
  2. <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
  3. layout="vertical"
  4. verticalAlign="middle"
  5. backgroundColor="white">
  6. <mx:Script>
  7. <![CDATA[
  8. import mx.events.ItemClickEvent;
  9. import mx.controls.tabBarClasses.Tab;
  10. private function tabBar_creationComplete():void {
  11. var colorArr:Array = ["red", "haloOrange", "yellow", "haloGreen", "haloBlue"];
  12. var color:String;
  13. var tab:Tab;
  14. var idx:uint;
  15. var len:uint = tabBar.dataProvider.length;
  16. for (idx = 0; idx < len; idx++) {
  17. var i:int = idx % colorArr.length;
  18. color = colorArr[i];
  19. tab = Tab(tabBar.getChildAt(idx));
  20. tab.setStyle("fillColors", [color, "white"]);
  21. tab.setStyle("fillAlphas", [1.0, 1.0]);
  22. tab.setStyle("backgroundColor", color);
  23. }
  24. }
  25. private function tabBar_itemClick(evt:ItemClickEvent):void {
  26. viewStack.selectedIndex = evt.index;
  27. }
  28. ]]>
  29. </mx:Script>
  30. <mx:Arrayid="arr">
  31. <mx:Objectlabel="Red" />
  32. <mx:Objectlabel="Orange" />
  33. <mx:Objectlabel="Yellow" />
  34. <mx:Objectlabel="Green" />
  35. <mx:Objectlabel="Blue" />
  36. </mx:Array>
  37. <mx:TabBarid="tabBar"
  38. dataProvider="{arr}"
  39. creationComplete="tabBar_creationComplete();"
  40. itemClick="tabBar_itemClick(event);"/>
  41. <mx:ViewStackid="viewStack"
  42. width="{tabBar.width}"
  43. styleName="plain">
  44. <mx:VBoxid="redVBox" width="100%" height="100">
  45. <mx:Labeltext="Red VBox" />
  46. </mx:VBox>
  47. <mx:VBoxid="orangeVBox" width="100%" height="100">
  48. <mx:Labeltext="Orange VBox" />
  49. </mx:VBox>
  50. <mx:VBoxid="yellowVBox" width="100%" height="100">
  51. <mx:Labeltext="Yellow VBox" />
  52. </mx:VBox>
  53. <mx:VBoxid="greenVBox" width="100%" height="100">
  54. <mx:Labeltext="Green VBox" />
  55. </mx:VBox>
  56. <mx:VBoxid="blueVBox" width="100%" height="100">
  57. <mx:Labeltext="Blue VBox" />
  58. </mx:VBox>
  59. </mx:ViewStack>
  60. </mx:Application>

你可能感兴趣的:(xml,Flex,Adobe)