12-30-2011 02:17 PM
Hello,
I'm trying to change the text colour on the buttons of a SegmentedControl and on the list part of a DropDown.
I don't want to change the skin, but only the actual text. With the DropDown I managed to change the top part (just what you see when the DropDown is closed) using
myDropDown.button.setTextFormatForState(myUpColor, SkinStates.UP);
etc., but with the elements inside the list and the SegmentedControl buttons I just can't find a property that would let me set the text format ...
Any ideas?
Solved! Go to Solution.
01-03-2012 01:18 PM
There doesn't seem to be any easy way to do this.
The only way would be to extend the SegmentedControl and then override the following method with the following code. It should do the trick. We'll work on making this easier in future updates.
override protected function onButtonAdded(child : RadioButton) : void
{
var dpLength : int = __dataProvider.length;
child.width = Math.round( width / dpLength );
// change this to be percentages
child.groupname = __groupName;
//Set your formats to whatever you like here.
child.setTextFormatForState( ThemeGlobals.getTextFormat( ThemeGlobals.SEGMENTED_CONTROL_FORMAT_DISABLED ), SkinStates.DISABLED );
child.setTextFormatForState( ThemeGlobals.getTextFormat( ThemeGlobals.SEGMENTED_CONTROL_FORMAT_OUT ), SkinStates.UP );
child.setTextFormatForState( ThemeGlobals.getTextFormat( ThemeGlobals.SEGMENTED_CONTROL_FORMAT_DOWN ), SkinStates.DOWN );
child.setTextFormatForState( ThemeGlobals.getTextFormat( ThemeGlobals.SEGMENTED_CONTROL_FORMAT_SELECTED ), SkinStates.SELECTED );
child.setTextFormatForState( ThemeGlobals.getTextFormat( ThemeGlobals.SEGMENTED_CONTROL_FORMAT_SELECTED_DIS ABLED ), SkinStates.DISABLED_SELECTED );
child.drawNow();
// set the button text formats here
}
01-04-2012 03:08 PM
Awesome, thanks Julian! Can you give me another pointer how to get at the text in the list part of a DropDown?
For anyone else who wants to customize the SegmentedControl, here is my version of the custom class (with a couple of slight changes to the code above since __dataProvider and __groupName are private):
public class AMP_SegmentedCtrl_PB extends SegmentedControl
{
// define your TextFormats
// ...
// unique number for each SegmentedControl, starting at 0
private static var counter:int = -1;
public function AMP_SegmentedCtrl_PB()
{
super();
counter++
}
override protected function onButtonAdded(child : RadioButton) : void
{
// set button width
var dpLength : int = dataProvider.length;
child.width = Math.round( width / dpLength );
// set group name (needs to be "0SegmentedRadioGroup", "1SegmentedRadioGroup" etc.)
child.groupname = counter + "SegmentedRadioGroup";
//Set your formats to whatever you like here.
child.setTextFormatForState( disabledFormat, SkinStates.DISABLED );
child.setTextFormatForState( upFormat, SkinStates.UP );
child.setTextFormatForState( downFormat, SkinStates.DOWN );
child.setTextFormatForState( selectedFormat, SkinStates.SELECTED );
child.setTextFormatForState( disabledSelectedFormat, SkinStates.DISABLED_SELECTED );
child.drawNow();
}
}Thanks a lot
Anna
01-09-2012 07:21 AM
To get at text in the list you will want to create a custom CellRenderer class. You can subclass CellRenderer if you like, or you can create your own class and implement the ICellRenderer interface.
Then you can set the DropDown.listSkin() with a reference to your class.
01-09-2012 09:09 AM
ah, sorry, yes - now I get it! (I had looked into implementing the ICellRenderer before, but somehow overlooked that the CellRenderer already gives me a setTextFormatForState() method - doh!)
Thanks a lot for the hint!