Creating a custom skin on the Spark TabBar control in Flex 4

The following example shows how you can create a custom RadioButton based skin on the Spark TabBar control in Flex 4 by setting the skinClass style.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/10/10/creating-a-custom-skin-on-the-spark-tabbar-control-in-flex-4/ -->
<s:Application name="Spark_TabBar_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/mx">
 
    <s:VGroup horizontalAlign="center"
            horizontalCenter="0" verticalCenter="0">
        <mx:ViewStack id="vs" width="300" height="100">
            <s:NavigatorContent label="One"
                    backgroundColor="red"
                    width="100%" height="100%" />
            <s:NavigatorContent label="Two"
                    backgroundColor="haloOrange"
                    width="100%" height="100%" />
            <s:NavigatorContent label="Three"
                    backgroundColor="Yellow"
                    width="100%" height="100%" />
            <s:NavigatorContent label="Four"
                    backgroundColor="haloGreen"
                    width="100%" height="100%" />
            <s:NavigatorContent label="Five"
                    backgroundColor="haloBlue"
                    width="100%" height="100%" />
        </mx:ViewStack>
        <s:TabBar dataProvider="{vs}" skinClass="skins.CustomSparkTabBarSkin" />
    </s:VGroup>
 
</s:Application>

And the custom Spark TabBar skin class, skins/CustomSparkTabBarSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/10/10/creating-a-custom-skin-on-the-spark-tabbar-control-in-flex-4/ -->
<spark:TabBarSkin name="CustomSparkTabBarSkin"
        xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:spark="spark.skins.spark.*">
 
    <s:DataGroup id="dataGroup" width="100%" height="100%">
        <s:layout>
            <s:ButtonBarHorizontalLayout gap="-1"/>
        </s:layout>
        <s:itemRenderer>
            <fx:Component>
                <s:RadioButton />
            </fx:Component>
        </s:itemRenderer>
    </s:DataGroup>
 
</spark:TabBarSkin>

View source is enabled in the following example.

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

3 thoughts on “Creating a custom skin on the Spark TabBar control in Flex 4

  1. I’m trying to use something similar except I have

    I’m looking for a way to swap out the Type of item in the inline renderer so as to achive decoupling.

    I want to use multiple app specific components which extend my CustomButtonBarButton but all use the same skin.

    Is this achivable without making a diferent skin for each?

      1. why doesn’t it work…?

        well : inside the fx component tag I have a CustomButtonBarButton with a skinClass

        that’s basically it

Comments are closed.