In Delphi XE2 FireMonkey - How to change the color of a button after clicking

I just want to change the color of the button after clicking on it.

Do I need to use "styles" for this or ...?

+5
source share
2 answers

You can change the button.StyleLookup property to change the style (color).

You need to add a new style to the style book.

  • Select "Edit custom style ..." in the right-click menu with the button.
  • Change the Fill.Color property on TRectangle elements in the background: TRectangle
  • Apply and close stylesheet
  • Clear button.stylelookup
  • Change button.stylelookup in buttonclick to a new creation style when you have not changed its name Button1Style1
+5

.

  • " ..." .
  • "" "" .

. , , .

OnClick , :

  var
    r: TRectangle;
  begin
    // Find the background TRectangle style element for the button
    r := (Button1.FindStyleResource('background') as TRectangle);
    if Assigned(r) then
    begin
      r.Fill.Color := claBlue;
    end;
  end;

: FMX.Objects , . TRectangle.

...

, . - . stylename TColorAnimation , . colorolimation1 coloranimation2 TColorAnimations.

:

var
  r: TRectangle;
  ca: TColorAnimation;
begin
  // Find the background TRectangle style element for the button
  r := (Button1.FindStyleResource('background') as TRectangle);
  if Assigned(r) then
  begin
    r.Fill.Color := claBlue;
  end;
  ca := (Button1.FindStyleResource('coloranimation1') as TColorAnimation);
  if Assigned(ca) then
  begin
    ca.StartValue := claBlue;
  end;
  ca := (Button1.FindStyleResource('coloranimation2') as TColorAnimation);
  if Assigned(ca) then
  begin
    ca.StopValue := claBlue;
  end;

: FMX.Ani TColorAnimation.

+1

All Articles