Changing a Button control’s text color

The following example shows how you can control the Button control’s text color using the color, disabledColor, textRollOverColor, and textSelectedColor styles.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/26/changing-a-button-controls-text-color/ -->
<mx:Application name="Button_color_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:ApplicationControlBar dock="true">
        <mx:Label text="color:" />
        <mx:ColorPicker id="colorCB" />
 
        <mx:Spacer width="33%" />
 
        <mx:Label text="textRollOverColor:" />
        <mx:ColorPicker id="textRollOverColorCB" />
 
        <mx:Spacer width="33%" />
 
        <mx:Label text="textSelectedColor:" />
        <mx:ColorPicker id="textSelectedColorCB" />
 
        <mx:Spacer width="33%" />
 
        <mx:Label text="disabledColor:" />
        <mx:ColorPicker id="disabledColorCB" />
        <mx:CheckBox id="enabledCh" label="enabled" selected="true" />
    </mx:ApplicationControlBar>
 
    <mx:Button id="button"
            label="Label"
            toggle="true"
            enabled="{enabledCh.selected}"
            color="{colorCB.selectedColor}"
            disabledColor="{disabledColorCB.selectedColor}"
            textRollOverColor="{textRollOverColorCB.selectedColor}"
            textSelectedColor="{textSelectedColorCB.selectedColor}" />
 
</mx:Application>

View source is enabled in the following example.

3 thoughts on “Changing a Button control’s text color

  1. Is it possible to change the font color of the “Selected Up” state? I think it would have to be done in a customized Button component.

  2. Nope.
    Set the stylename of the button by click to another Style with the color for selection. thats it.

Comments are closed.