【问题标题】:How to style Button with Apache Royale如何使用 Apache Royale 设置按钮样式
【发布时间】:2019-09-25 17:30:11
【问题描述】:

使用位于apache-royale-0.9.6-bin-js\royale-asjs\examples 的示例,我尝试更改按钮的背景或字体颜色。

所以,我找到了一个如何为js|TextButton 使用样式的示例,但我问了自己几个问题:

1) 如何用j|Button 做同样的事情?

2) 如果我想在 clic 上更改 j|Button 的颜色怎么办(搜索“setStyle”等效项)

这里是完整的代码:

<js:Application 
               xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:js="library://ns.apache.org/royale/basic" 
               xmlns:j="library://ns.apache.org/royale/jewel" >

    <fx:Style>
        @namespace j "library://ns.apache.org/royale/jewel";
        @namespace js "library://ns.apache.org/royale/basic";

        j|Button {
            color : #ffA3EE ; /*Has no effect, not sure I do the right things*/
        }

        js|TextButton {
            background-color: #fc0000;
            border-radius : 6px ;
            font-weight : normal ;
            line-height : 1.4 ;
            color : #ffA3EE ;
            font-size : 15px ;
            padding : 5px ;
        }

        js|TextButton:hover {
            background-color: #CFCFCF;
            vertical-align: middle;
            border: none;
            border-radius: 6px;
        }

        js|TextButton:active {
            background-color: #77CEFF;
            color: #FFFFFF;
        }
    </fx:Style>

    <fx:Script>
        <![CDATA[
            private function ev_clic_jbutton():void{
                //jbutton.setStyle("color",0x00ff00); // How to do to change color ?
            }
        ]]>
    </fx:Script>


    <js:valuesImpl>
        <js:SimpleCSSValuesImpl />
    </js:valuesImpl>

    <js:beads>
        <js:ApplicationDataBinding />
    </js:beads>

    <js:initialView>
        <js:View width="100" height="100" >

            <j:HGroup gap="10">
                <j:Button id="jbutton" click="ev_clic_jbutton()" text="J Button" width="100" height="100"/>
                <js:TextButton text="JS TextButton" width="100" height="100"/>
            </j:HGroup>

        </js:View>
    </js:initialView>
</js:Application>

问候

【问题讨论】:

    标签: button styles apache-royale


    【解决方案1】:

    对于 Jewel,样式是通过 CSS 修改的。选择器使用以下格式:.jewel.&lt;component-name&gt;。在 Jewel Button 的情况下,使用以下命令同时影响 所有 宝石按钮并将文本标签的颜色更改为红色:

        <fx:Style>
        .jewel.button
        {
            color: #ff0000;
        }
        </fx:Style>
    

    (如果需要,也可以在外部 CSS 文件中添加此选择器,而不是在 MXML 或 AS3 中)

    编译器将输出此选择器规则,而不是 Jewel Theme 中的选择器规则,因为您的项目优先。

    仅更改一个实例:

        .jewel.button.mystyle
        {
           color: #00ff00;
        }
    

    并使用它:

    <j:Button text="A Button" className="mystyle"/>
    

    上一个按钮会将文本标签的颜色更改为绿色。

    此外,您可以使用 j|Button 在运行时更改或添加珠子 (IBead)

    在基本组件的情况下,所有这些都是通过js|Button、珠子和 CSS 样式完成的。

    【讨论】:

    • 非常感谢,有效地在运行时更改样式我做了 jbutton.className = "mystyle_red" (在 CSS 中添加了 .jewel.button.mystyle_red 和颜色:#ff0000)并且它有效!我在哪里可以找到一个组件可用的所有样式名称? Docs 没有“风格”一章。我需要查看 Jewel Button SDK 源代码吗?
    • 嗨 Fred,很遗憾,现在您需要深入研究 Royale 中 Jewel 和 JewelTheme 项目中的 SASS 代码。这几天我正在研究文档,并且在具体的 Jewel 文档中也是如此。根据您的评论,您给了我为每个组件添加样式表的想法,例如按钮,这将在这里:apache.github.io/royale-docs/component-sets/jewel/button
    猜你喜欢
    • 2021-10-13
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    相关资源
    最近更新 更多