I am writing a memo component that needs to look like an old fashioned terminal session. This should be really simple, but the way FireMonkey styles work seem to make it unbelievably complex.
In a non mobile FireMonkey app I can right click a control and select "Edit Custom Style". This option is not available in mobile apps. Here's the reason given by one of the FireMonkey developers.
It is support different style on iOS and Android. We cannot run application on Android in iOS style. But when you try to change platform style, automatically we will use it on each target platform. If you want to change default style of fm control, you should put on the form style book and make style in it, or load to stylebook platform style and make changes in it.
Also very important, When you load platform style in style book, You can want that application instance will not have two copy of platform style (one - system in fmx package and other copy in your style book). For it you should to set flag true in TStylebook.UseStyleManager. In this case style in Style book will replace platform style.
OK, so I reckon I need to create a custom style. How do I go about creating a custom style to override only the font and background properties?
I guess I can override the ApplyStyle procedure something like this.
procedure TMyMemo.ApplyStyle;
var
BackgroundObject: TFmxObject;
begin
inherited;
BackgroundObject := FindStyleResource('content');
if Assigned(BackgroundObject) then
begin
// Change the background color of the background
end;
end;
How do I know what type the background object is and which property I need to change?
Surely, changing the background colour of a control can't be this difficult! Am I missing something fundamental with the FM styles?
Hope you find useful this workaround
uses System.UIConsts;
procedure TfPlanJob.mDetailApplyStyleLookup(Sender: TObject);
var Obj: TFmxObject;
Rectangle1: TRectangle;
begin
Obj := mDetail.FindStyleResource('background');
if Obj <> nil then
begin
TControl(Obj).Margins := TBounds.Create(TRectF.Create(-1, -1, -1, -1));
Rectangle1 := TRectangle.Create(Obj);
Obj.AddObject(Rectangle1);
Rectangle1.Align := TAlignLayout.Client;
Rectangle1.Fill.Color := claLightslategrey;
Rectangle1.Stroke.Color := claNull;
Rectangle1.HitTest := False;
Rectangle1.SendToBack;
end;
end;
Well one thing I found out is that the fonts can't be changed in FireMonkey! You can set it to a different font but when you run it on a device it will go to the default one.
If you want to change the background color for the memo you should add a stylebook to your form and load a style file you want(Like the default light iOS style). When you have loaded a style go to memostyle and change de background.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With