Change font color and TMemo background in FireMonkey

I am writing a memo component that should look like an old-fashioned terminal. It should be really simple, but the work of FireMonkey styles seems incredibly complex.

In the non-mobile FireMonkey application, I can right-click the control and select "Edit Custom Style." This option is not available in mobile applications. Here is the reason given by one of the FireMonkey developers.

This is a different style support on iOS and Android. We cannot run an Android app in the iOS style. But when you try to change the platform style, we will automatically use it on each target platform. If you want to change the default fm style, you must either put on a style book style and make a style in it, or load a platform style in the style book and make changes to it.

It is also very important that when you load the platform style into the style book, you may require that the application instance does not have two copies of the platform style (one is the system in the fmx package and the other copy in your style book). To do this, you must set the true flag in TStylebook.UseStyleManager. In this style of style, the style book will replace the platform style.

OK, so I think I need to create my own style. How do I create my own style to override only font and background properties?

I think I can redefine the ApplyStyle procedure 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 of background object and property I need to change?

Of course, changing the background color of a control cannot be that difficult! Did I miss something fundamental with FM styles?

+6
source share
2 answers

Well, I found out that fonts cannot be changed in FireMonkey! You can install it on a different font, but when you launch it on the device, it will switch to the standard ones.

If you want to change the background color for the note, you must add a stylesheet to your form and upload the style file you want (for example, the default iOS style). When you have loaded the style, go to memostyle and change the background.

Hope this helps!

+1
source

We hope you find this workaround useful.

 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; 
0
source

Source: https://habr.com/ru/post/954662/


All Articles