Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
apman
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified
Accepted Solution

Formating text on SegmentedControl and inside DropDown

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?

 

BlackBerry Development Advisor
jdolce
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Formating text on SegmentedControl and inside DropDown

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_DISABLED ), SkinStates.DISABLED_SELECTED );
			child.drawNow();
			// set the button text formats here
		}

 

Developer
apman
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Formating text on SegmentedControl and inside DropDown

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

 

 

BlackBerry Development Advisor
jdolce
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Formating text on SegmentedControl and inside DropDown

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.

Developer
apman
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Formating text on SegmentedControl and inside DropDown

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!