Changing the background color of a disabled Spark TextArea control in Flex 4

In a previous example, “Changing the background color of a disabled TextArea control in Flex”, we saw how you can change the background color of a disabled MX TextArea control by setting the use the backgroundDisabledColor style.

The following example shows how you can change the background color of a disabled Spark TextArea control in Flex 4 by setting the contentBackgroundColor style in the disabled skin state.

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/05/18/changing-the-background-color-of-a-disabled-spark-textarea-control-in-flex-4/ -->
<s:Application name="Spark_TextArea_contentBackgroundColor_disabled_text"
        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:layout>
        <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle" />
    </s:layout>
    <s:controlBarContent>
        <s:CheckBox id="cb"
                label="enabled"
                selected="true" />
    </s:controlBarContent>
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";
 
        s|TextArea {
            contentBackgroundColor: haloGreen;
        }
 
        s|TextArea:disabled {
            contentBackgroundColor: red;
        }
    </fx:Style>
 
    <s:TextArea id="txtArea1"
            text="The quick brown fox jumps over the lazy dog"
            enabled="{cb.selected}" />
 
    <s:TextArea id="txtArea2"
            text="The quick brown fox jumps over the lazy dog"
            enabled="{cb.selected}" />
 
</s:Application>

[GoogleAdsWide]

If you want to change the contentBackgroundColor style on an individual Spark TextArea control instead of globally you can add an identifier to the CSS declaration, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/05/18/changing-the-background-color-of-a-disabled-spark-textarea-control-in-flex-4/ -->
<s:Application name="Spark_TextArea_contentBackgroundColor_disabled_text"
        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:layout>
        <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle" />
    </s:layout>
    <s:controlBarContent>
        <s:CheckBox id="cb"
                label="enabled"
                selected="true" />
    </s:controlBarContent>
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";
 
        s|TextArea#txtArea1 {
            contentBackgroundColor: haloGreen;
        }
 
        s|TextArea:disabled#txtArea1 {
            contentBackgroundColor: red;
        }
    </fx:Style>
 
    <s:TextArea id="txtArea1"
            text="The quick brown fox jumps over the lazy dog"
            enabled="{cb.selected}" />
 
    <s:TextArea id="txtArea2"
            text="The quick brown fox jumps over the lazy dog"
            enabled="{cb.selected}" />
 
</s:Application>

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.