26
Aug
07

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.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/26/changing-a-button-controls-text-color/ -->
<mx:Application 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.


2 Responses to “Changing a Button control's text color”


  1. 1 Umer Jul 30th, 2008 at 11:59 pm

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

  2. 2 Adam Sep 10th, 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.

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed