08
Nov
08

Setting text styles for a selected button in a ToggleButtonBar control in Flex

The following example shows how you can set the text color for the selected button in a Flex ToggleButtonBar control by setting the selectedButtonTextStyleName style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/08/setting-text-styles-for-a-selected-button-in-a-togglebuttonbar-control-in-flex/ -->
<mx:Application name="ToggleButtonBar_selectedButtonTextStyleName_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        .mySelectedButtonTextStyleName {
            color: haloBlue;
        }
    </mx:Style>

    <mx:Array id="arr">
        <mx:Object label="One Fish" />
        <mx:Object label="Two Fish" />
        <mx:Object label="Red Fish" />
        <mx:Object label="Blue Fish" />
    </mx:Array>

    <mx:ToggleButtonBar id="toggleButtonBar"
            selectedButtonTextStyleName="mySelectedButtonTextStyleName"
            dataProvider="{arr}" />

</mx:Application>

1 Response to “Setting text styles for a selected button in a ToggleButtonBar control in Flex”


  1. 1 zuccaralloo Nov 11th, 2008 at 1:13 am

    How do you do the same thing with simple buttons - setting text style when selected? My workaround right now is having a condition in the styleName property. Is there a simpler/better way? Any property I have missed?

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

  • Powered by Redoable 1.2
  • Cornify
  • Feeds burnt by Feedburner
  • Feed