Changing the background fill colors on a ComboBox control in Flex

The following example shows how you can change the background fill colors for a Flex ComboBox control by setting the fillColors style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/14/changing-the-background-fill-colors-on-a-combobox-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
    </mx:Array>

    <mx:ComboBox id="comboBox"
            dataProvider="{arr}"
            fillColors="[red, haloOrange]" />

</mx:Application>

View source is enabled in the following example.

You can also set the fillColors style in an external .CSS file or <mx:Style /> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/14/changing-the-background-fill-colors-on-a-combobox-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Style>
        ComboBox {
            fillColors: red, haloOrange;
        }
    </mx:Style>

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
    </mx:Array>

    <mx:ComboBox id="comboBox"
            dataProvider="{arr}" />

</mx:Application>

Or, you can set the fillColors style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/14/changing-the-background-fill-colors-on-a-combobox-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function init():void {
                comboBox.setStyle("fillColors", ["red", "haloOrange"]);
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
    </mx:Array>

    <mx:ComboBox id="comboBox"
            dataProvider="{arr}"
            creationComplete="init();" />

</mx:Application>