Flex 中的 CSS 寻址:仅 RichTextEditor 中的按钮?
我想要更改 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 RichTextEditor 的子组件是在 MXML 中声明的,因此可以公开访问,因此一种方法是在运行时(在容器的
creationComplete
之后)单独分配它们的styleName
属性。事件触发,以确保编辑器及其所有子组件都已创建),如下所示: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'screationComplete
event fires, to be sure the editor and all its children have been created), like so: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 styleableicon
property, not font-style settings, for their look and feel.Hope it helps!
谢谢@Christian Nunciato! 这是我的最终代码,在我的组件中,它是一个 RichTextEditor (扩展它)。 在creationComplete中,我称之为这个
,然后在我的样式表中,我有这个
Awesome。 再次感谢!
Thanks @Christian Nunciato! This is my final code, in my component that is a RichTextEditor (extends it). In the creationComplete, I call this
and then in my styleSheet, I have this
Awesome. Thanks again!