Styling individual tabs in a TabBar control

简介:
following example shows how you can style individual tabs in a Flex TabBar control by calling the  getChildAt()  method on the tab bar, and then calling  setStyle()  on the returned Tab reference.

A big thanks to Joan for helping me figure it out

<? xml version="1.0" ?>
<!--  http://blog.flexexamples.com/2007/11/19/styling-individual-tabs-in-a-tabbar-control/  -->
< 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 >



    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2008/01/13/1037060.html ,如需转载请自行联系原作者

相关文章
|
8月前
|
JavaScript
解决 NavigationDuplicated: Avoided redundant navigation to current location: “/“
解决 NavigationDuplicated: Avoided redundant navigation to current location: “/“
145 0
解决 NavigationDuplicated: Avoided redundant navigation to current location: “/“
|
JavaScript
tabs
tabs
70 0
tabs
|
JavaScript Go
解决 vue-router 报错:Navigation cancelled from “/...“ to “/...“ with a new navigation
解决 vue-router 报错:Navigation cancelled from “/...“ to “/...“ with a new navigation
748 1
解决 vue-router 报错:Navigation cancelled from “/...“ to “/...“ with a new navigation
click Edit button in Opportunity - why curr is displayed wrongly
click Edit button in Opportunity - why curr is displayed wrongly
70 0
click Edit button in Opportunity - why curr is displayed wrongly
how is bookmark function implemented in Opportunity
how is bookmark function implemented in Opportunity
102 0
how is bookmark function implemented in Opportunity
how cross component navigation is achieved
how cross component navigation is achieved
how cross component navigation is achieved
why is list delete and edit icon rendered
Created by Wang, Jerry, last modified on Feb 17, 2015
88 0
why is list delete and edit icon rendered