Search code examples
delphifiremonkey

how to change, disabled button color FMX?


When using StyleBook, if button is Diasbled the color hardly describes that the button is disabled. I therefore want to change the color when the button is disabed. How do I do that. I am using Delphi Seattle


Solution

  • That's not as straight-forward as changing the normal color in the Style Book. The disabled look is achieved by lowering the opacity of the control rather than by adjusting any of the color properties.

    What I would do is to first create a style for the disabled button, using whichever colors you like. Whenever you disable the button, you can set the button's StyleLookup to that style's name, and change it back to the default if you enable it again.

    In addition to that, you might want to disable the usual behavior of adjusting the opacity. Therefor you need to set the DisabledOpacityof the button. You can't usually access that property, but you can crack it open by subclassing it.

    type
      TMyButton = class (TButton);
    
    // ...
    
    TMyButton(Button1).DisabledOpacity := 1.0;