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

by Peter deHaan on November 8, 2008

in ToggleButtonBar

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 comment… read it below or add one }

1 zuccaralloo November 11, 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?

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: