In a previous example, “Setting the base color on the Halo DataGrid control in Flex 4″, we saw how you could set the base/theme color on a Halo DataGrid control (with the default Spark skin) in Flex 4 by setting the baseColor style.

The following example shows how you can set gradient header colors on the Halo DataGrid control (with the default Spark skin) in Flex 4 by creating a custom DataGrid header background skin and setting the headerBackgroundSkin style.

Full code after the jump.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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/2009/07/19/setting-the-header-colors-on-the-halo-datagrid-control-in-flex-4/ -->
<s:Application name="Spark_DataGrid_headerBackgroundSkin_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">
 
    <mx:DataGrid id="dataGrid"
            headerBackgroundSkin="skins.CustomDataGridHeaderBackgroundSkin"
            horizontalCenter="0" verticalCenter="0">
        <mx:dataProvider>
            <mx:ArrayList source="{Font.enumerateFonts(true)}" />
        </mx:dataProvider>
    </mx:DataGrid>
 
</s:Application>

And the custom header background skin class, skins/CustomDataGridHeaderBackgroundSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/07/19/setting-the-header-colors-on-the-halo-datagrid-control-in-flex-4/ -->
<s:SparkSkin name="CustomDataGridHeaderBackgroundSkin"
             xmlns:fx="http://ns.adobe.com/mxml/2009"
             xmlns:s="library://ns.adobe.com/flex/spark"
             minWidth="21" minHeight="19">
 
    <!-- layer 2: fill -->
    <s:Rect left="0" right="0" top="0" bottom="0">
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="haloBlue" alpha="0.85" />
                <s:GradientEntry color="haloGreen" alpha="0.85" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>
 
    <!-- layer 3: fill lowlight -->
    <s:Rect left="0" right="0" bottom="0" height="9">
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="0x000000" alpha="0.0099" />
                <s:GradientEntry color="0x000000" alpha="0.0627" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>
 
    <!-- layer 4: fill highlight -->
    <s:Rect left="0" right="0" top="0" height="9">
        <s:fill>
            <s:SolidColor color="0xFFFFFF" alpha="0.33" />
        </s:fill>
    </s:Rect>
 
    <!-- layer 7: border - put on top of the fill so it doesn't disappear when scale is less than 1 -->
    <s:Rect left="0" right="0" bottom="0" height="1">
        <s:fill>
            <s:SolidColor color="#696969" />
        </s:fill>
    </s:Rect>
 
</s:SparkSkin>

(DataGrid header background skin copied from the <Flex SDK>\frameworks\projects\sparkskins\src\mx\skins\spark\DataGridHeaderBackgroundSkin.mxml template.)

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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

2 Responses to Setting the header colors on the Halo DataGrid control in Flex 4

  1. Tushar says:

    Hi Peter,
    thanks for providing this ex. I want to set this skin class through CSS. can you please help me.

    Thanks. :)

  2. Bene says:

    Hi Peter,
    which is the host component that you used to create the skin?

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree