Flex 中的 CSS 寻址:仅 RichTextEditor 中的按钮?

发布于 2024-07-13 04:58:26 字数 131 浏览 7 评论 0原文

我想要更改 RichTextEditor 工具栏中按钮的字体特征,但我希望它们与应用程序中的其他按钮不同。 有什么方法可以只用CSS来做到这一点吗?我知道如果有必要我可以用setStyle来做到这一点......

I want to change the font characteristics for buttons in the toolbar of the RichTextEditor, but I want them to be different than other buttons in my application. Is there any way to do this with just CSS? I know that I can do it with setStyle if necessary...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一绘本一梦想 2024-07-20 04:58:27

由于 RichTextEditor 的子组件是在 MXML 中声明的,因此可以公开访问,因此一种方法是在运行时(在容器的 creationComplete 之后)单独分配它们的 styleName 属性。事件触发,以确保编辑器及其所有子组件都已创建),如下所示:

<mx:Style>

    .myRTECombo
    {
        color: #FF0000;
    }

</mx:Style>

<mx:Script>
    <![CDATA[

        private function creationCompleteHandler(event:Event):void
        {
            rte.fontFamilyCombo.styleName = "myRTECombo";
            rte.fontSizeCombo.styleName = "myRTECombo";
        }

    ]]>
</mx:Script>

<mx:RichTextEditor id="rte" />

Flex 文档不会通过 ID 调用子组件(“boldButton”、“fontSizeCombo”等),但组件的源是可供查看,因此您应该能够从源代码本身获取所需的所有信息。 由于我使用 FlexBuilder,我通常使用 Eclipse Ctrl+单击快捷方式,在标签/类名称上,跳转到关联的类定义文件,但您也可以直接在 [installDir]/sdks/[version ]/frameworks/src/mx/RichTextEditor.mxml 自己看看。

我确信还有其他方法(setStyle 是其中一种,尽管出于性能原因通常不鼓励显式使用它),但这应该适合您。 不过,需要注意的一件事是,当您深入研究组件的源代码时,您会看到,默认按钮集中的许多按钮实际上使用 PNG(例如,icon_style_bold.png),而不是文本,这就是为什么我的示例包含对 ComboBox 的引用,这样您就可以看到颜色更改是如何应用的; 如果您想更改按钮的外观,请注意它们使用的是可样式化的图标属性,而不是字体样式设置来实现其外观和感觉。

希望能帮助到你!

One way to do it, since the RichTextEditor's sub-components are declared in MXML and are therefore publicly accessible, is to assign their styleName properties individually at runtime (after the container's creationComplete event fires, to be sure the editor and all its children have been created), like so:

<mx:Style>

    .myRTECombo
    {
        color: #FF0000;
    }

</mx:Style>

<mx:Script>
    <![CDATA[

        private function creationCompleteHandler(event:Event):void
        {
            rte.fontFamilyCombo.styleName = "myRTECombo";
            rte.fontSizeCombo.styleName = "myRTECombo";
        }

    ]]>
</mx:Script>

<mx:RichTextEditor id="rte" />

The Flex docs don't call out the subcomponents ("boldButton", "fontSizeCombo", et al) by ID, but the component's source is available for viewing, so you should be able to get all the info you need from the source code itself. Since I use FlexBuilder, I usually use the Eclipse Ctrl+click shortcut, on the tag/class name, to jump into the associated class-definition file, but you can also open the source file directly at [installDir]/sdks/[version]/frameworks/src/mx/RichTextEditor.mxml to have a look for yourself.

I'm sure there are other approaches (setStyle being one, although its explicit use is generally discouraged for performance reasons), but this ought to work out for you. One thing to note, though, as you'll see when you dig into the component's source, is that many of the buttons in the default button set actually use PNGs (e.g., icon_style_bold.png), not text, which is why my example includes a reference to the ComboBox instead, so you can see how the color changes apply; if you want to change the look of the buttons, be aware they're using the styleable icon property, not font-style settings, for their look and feel.

Hope it helps!

乱世争霸 2024-07-20 04:58:27

谢谢@Christian Nunciato! 这是我的最终代码,在我的组件中,它是一个 RichTextEditor (扩展它)。 在creationComplete中,我称之为这个

private function setUpStyleNames():void {
    setUpStyleNamesInner(toolbar.getChildren());
    setUpStyleNamesInner(toolBar2.getChildren());
}

private function setUpStyleNamesInner(children:Array):void {
    for each (var child:DisplayObject in children) {
        if (child is UIComponent) {
            UIComponent(child).styleName = "rteInnards";
        }
    }
}

,然后在我的样式表中,我有这个

.rteInnards {
    color: #FF0000;
    fontSize: 25px;
}

Awesome。 再次感谢!

Thanks @Christian Nunciato! This is my final code, in my component that is a RichTextEditor (extends it). In the creationComplete, I call this

private function setUpStyleNames():void {
    setUpStyleNamesInner(toolbar.getChildren());
    setUpStyleNamesInner(toolBar2.getChildren());
}

private function setUpStyleNamesInner(children:Array):void {
    for each (var child:DisplayObject in children) {
        if (child is UIComponent) {
            UIComponent(child).styleName = "rteInnards";
        }
    }
}

and then in my styleSheet, I have this

.rteInnards {
    color: #FF0000;
    fontSize: 25px;
}

Awesome. Thanks again!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文