Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Using Styles</strong></p> <p>An alternative to creating a different style and switching to that new style would be creating a custom style for the button and changing the color in that style at run time.</p> <ol> <li>Right-click the button and select 'Edit custom style...' from the main menu.</li> <li>Click Apply and Close in the style editor.</li> </ol> <p>You've just created a custom style for the button. So when you edit it at run time, it will only affect that button.</p> <p>Now, enter the following in your OnClick event to change the color at run time:</p> <pre><code> 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; </code></pre> <p>Note: Add FMX.Objects to your uses clause if you don't already have it. That's where TRectangle is.</p> <p><strong>But wait...</strong></p> <p>You'll notice that the button's color changes back to the default when the mouse leave or enters the button. That's due to the animations. If you set the stylename properties for both of the TColorAnimation style elements in the style editor for the custom style, you can also set the color on those. For my example, I've named the TColorAnimations coloranimation1 and coloranimation2.</p> <p>Here's the revised code:</p> <pre><code>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; </code></pre> <p>Note: Add FMX.Ani to your uses clause for TColorAnimation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload