Changing a Button control’s text color

by Peter deHaan on August 26, 2007

in Button

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 comments… read them below or add one }

1 Umer July 30, 2008 at 11:59 pm

how can i chagned the background color of button? on mouseover

Reply

2 Adam September 10, 2008 at 8:52 am

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.

Reply

3 screenworker January 28, 2010 at 8:28 am

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

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: