简体   繁体   English

更改Flex切换按钮的背景颜色

[英]Change the background color of a Flex toggle button

What is the easiest way to change the background color of a toggle button when it is selected? 选择切换按钮时,最简单的更改背景颜色的方法是什么?

I've tried creating a custom skin for the button and applying it to the downSkin property, but I can't figure out how to change the background color from within the skin. 我尝试为按钮创建自定义外观并将其应用到downSkin属性,但是我不知道如何从外观中更改背景颜色。 Also I'd like to avoid using an image as a background if possible. 另外,如果可能的话,我也想避免使用图像作为背景。

I hope I understand what you need. 希望我了解您的需求。

In your skin file, the state upAndSelected is what you need to specify the color when the togglebutton is selected. 在皮肤文件中,状态upAndSelected是选择切换按钮时需要指定颜色的状态。 You can copy the generated skin code from Flex to modify it or check the code below. 您可以从Flex复制生成的外观代码以对其进行修改,也可以检查以下代码。 Add it below the </s:Rect> tag under <!-- layer 2: fill @private-->` 将其添加到<!--第2层下的</s:Rect>标记下:填充@private->`

<s:Rect id="fill2" left="1" right="1" top="1" bottom="1" radiusX="2">
    <s:fill>
        <s:LinearGradient rotation="90">
        <s:GradientEntry color="0xFFFFFF"
                         color.upAndSelected="#333333" // you can modify color here
                         alpha="0.85" 
                         />

        <s:GradientEntry color="0xD8D8D8" 
                         color.upAndSelected="red" // you can modify color here 
                         alpha.downAndSelected="1" />
        </s:LinearGradient>
    </s:fill>
</s:Rect>

Paste the code above under 将上面的代码粘贴到

 <!-- layer 2: fill -->
    <!--- @private -->
    <s:Rect id="fill" left="1" right="1" top="1" bottom="1" radiusX="2">
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="0xFFFFFF" 
                               color.selectedUpStates="0xBBBDBD"
                               color.overStates="0xBBBDBD" 
                               color.downStates="0xAAAAAA" 
                               alpha="0.85" 
                               alpha.overAndSelected="1" />
                <s:GradientEntry color="0xD8D8D8" 
                               color.selectedUpStates="0x9FA0A1"
                               color.over="0x9FA0A1" 
                               color.overAndSelected="0x8E8F90"
                               color.downStates="0x929496" 
                               alpha="0.85"
                               alpha.overAndSelected="1" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>

Hope it helps. 希望能帮助到你。

No easy way. 没有简单的方法。 Your best bet is to open up Flash Professional and create a skin; 最好的选择是打开Flash Professional并创建外观。 then assign that skin to the button as a style using something like this: 然后使用如下样式将该外观分配给按钮作为样式:

MyButton.setStyle('skin', mySkin);

[This advice may not apply if you are referring to a Spark ToggleButton as opposed to a Halo ToggleButton[ [如果您指的是Spark ToggleButton,而不是Halo ToggleButton,则此建议可能不适用[

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM