12-29-2012 08:56 PM
Wondering if anyone has had any success changing the text format of a SegmentedControl in BB10?
I have tried the example here but it doesn't seem to work. Mainly, I am just trying yo change the font color of each item.
Any suggestions appreciated. Thanks.
12-30-2012 09:05 AM
12-30-2012 03:08 PM
I have not tried the CSS method as I am little uncertain how to target the specific elements of the SegmentenControl. Thanks for the suggestion though, I will look into how to do that.
12-30-2012 07:27 PM - edited 12-30-2012 07:32 PM
To use the setTextFormatForState method, you actually need to override the SegmentedCtrl class. This is a slightly adapted version of what Julian Dolce explained to me when I had the same problem a year ago with the PlayBook:
package
{
import qnx.fuse.ui.buttons.RadioButton;
import qnx.fuse.ui.buttons.SegmentedControl;
import qnx.fuse.ui.skins.SkinStates;
/**
* Override QNX default formatting for SegmentedCtrl
*/
public class MySegmentedCtrl extends SegmentedControl
{
private static var counter:int = -1;
private var id:uint;
public function MySegmentedCtrl()
{
super();
// In order to give each Segmented Control a unique id,
// keep a running counter and store the current number
// for each instance (if you have several controls they
// may all be created, before the first one starts
// adding its buttons)
counter++;
id = 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 (not just any name!
// must be "0SegmentedRadioGroup", "1SegmentedRadioGroup" etc.)
child.groupname = id + "SegmentedRadioGroup";
//Set your formats to whatever you like here.
child.setTextFormatForState( MyFormats.UP, SkinStates.UP );
child.setTextFormatForState( MyFormats.SELECTED, SkinStates.DOWN );
child.setTextFormatForState( MyFormats.SELECTED, SkinStates.SELECTED );
child.setTextFormatForState( MyFormats.DISABLED, SkinStates.DISABLED );
child.setTextFormatForState( MyFormats.DISABLED_SELECTED, SkinStates.DISABLED_SELECTED );
}
}
}
With that class in place you then use new MySegmentedCtrl() instead of new SegmentedControl() and otherwise procede as normal.
My app : Get set - Get up! Get ready for the snooze revolution.