简体   繁体   English

Flex按钮左侧有一种颜色,右侧有另一种颜色

[英]Flex Button with one color on left & another on right

I have a Flex button. 我有一个Flex按钮。 I need one color on the left and another on the right. 我需要一种颜色在左边,另一种在右边。 I don't need it to be a gradient. 我不需要它是渐变的。 Just solid colors. 只是纯色。 Like green on left & red on right. 就像左边的绿色和右边的红色。 I really don't want to use an image -- just because it'll probably take me a long time to do it. 我真的不希望使用的图像 - 只是因为它很可能要花费很长一段时间来做到这一点。

The gradients via Flex Properties in Flex Builder seems to apply only vertically, not horizontally. 通过Flex Builder中的Flex属性进行的渐变似乎仅适用于垂直方向,不适用于水平方向。

I also tried to make 2 button, each half width (of original), and putting it into a HBox & really packing them close so they'll look like a single button with 2 colors. 我还尝试制作2个按钮,每个按钮的宽度为原始宽度的一半,然后将其放入HBox中,然后将它们紧密包装,以使它们看起来像是具有2种颜色的单个按钮。 It works OK, but I was thinking if there was a better way. 可以,但是我在想是否有更好的方法。

Thanks. 谢谢。

I think the proper way to do something like this is to create a custom component and then override the drawing method and draw in two colors, with the associated properties and such. 我认为做这样的事情的正确方法是创建一个自定义组件,然后覆盖绘图方法,并绘制两种颜色以及相关的属性。

The solution you used is the simplest, so you should keep it like that unless you want to go through the trouble of creating the custom component (It's not THAT bad since Flex is open source and you can see how the original button is coded, and modify from there). 您所使用的解决方案是最简单的,所以你应该保持这样的,除非你想通过创建自定义组件的麻烦(这不是那么糟糕,因为Flex是开源的,你可以看到原来的按钮是如何编码,从那里修改)。

你可以用degrafa来给按钮贴皮

This link http://blog.timeister.com/2009/01/16/flex-custom-button-skin/ provides a nice way to do exactly what I wanted above. 此链接http://blog.timeister.com/2009/01/16/flex-custom-button-skin/提供了一种很好的方法来精确地完成我上面想要的操作。 It needs 2 classes: one subclasses ButtonSkin & the other Button. 它需要2个类:一个子类ButtonSkin和另一个Button。 Link them both via CSS and use them in mxml. 通过CSS链接它们,并在mxml中使用它们。 Simple & easy. 简单容易。

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

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