无法更改Flex中的字体 - Spark RadioButton

时间:2014-07-09 10:34:55

标签: flex actionscript

我正在尝试更改我在运行时创建的Spark Radiobutton的字体大小和系列:

            var radio:RadioButton = new RadioButton;

            radio.layoutDirection = "rtl";

            var format:TextFormat = new TextFormat();
            format.font = "Tahoma";
            format.color = 0x336699;
            format.size = 13;

            radio.setStyle("embedFonts", true);
            radio.setStyle("textFormat", format);

            radio.label = text;

            radio.groupName = "radiogrp_" + index.toString();
            hgrp.addElement(radio);

无论我尝试什么,字体保持不变。家庭和大小都是默认的。

感谢。

3 个答案:

答案 0 :(得分:0)

尝试

var radio:RadioButton = new RadioButton;

radio.layoutDirection = "rtl";

radio.setStyle("embedFonts", true);
radio.setStyle("fontFamily", "Tahoma");
radio.setStyle("color", 0x336699);
radio.setStyle("fontSize", 13);

答案 1 :(得分:0)

我试试这个有效

var radio:RadioButton = new RadioButton();
radio.addEventListener(FlexEvent.CREATION_COMPLETE, onRadioAddHandler);

radio.label = "Some text";
radio.x = 200;

this.addElement(radio);

处理程序

private function onRadioAddHandler(event:Event):void {
    var radio:RadioButton = RadioButton(event.target);

    radio.layoutDirection = "rtl";

    radio.setStyle("fontFamily", "Tahoma");
    radio.setStyle("color", 0x336699);
    radio.setStyle("fontSize", 25);
}

答案 2 :(得分:0)

定义一个不错的TextFormat,然后将其与setStyle一起使用:

attribFormat = new TextFormat(null, fontsize, 0x000000, null, null,null,null,null,"left");
myRadio.setStyle("textFormat", attribFormat);

希望它有所帮助!