Firemonkey TButton style with two different texts

I am trying to create a virtual keyboard where each button has both a number and multiple letters. For example, a number 2

will also have text ABC

next to it in a smaller font size, and a number 3

will have text DEF

next to it.

I can successfully edit the custom style of these buttons one by one. One button, I can remove the style element TText

, change the alignment and text settings for each and it works great ...

Designing a Button Style

However, I have to do this one by one, styling each button on its own. If I try to reuse this style, the additional letters ABC

are the same for all keys. But I need them to be different.

Sample keyboard at runtime

How can I create one reusable style that can also allow me to use different subtexts in each button? Or do I need to create a unique style for each button?

+3


source to share


1 answer


You can do a workaround, set the StyleName

ABC Label text to text and the StyleName of the label number to the number.

Create a class that overrides the button class.



TButton = class(FMX.StdCtrls.TButton)
protected
  procedure ApplyStyle; override;
end;

procedure TButton.ApplyStyle;
  var NumberLabel : TLabel;
begin
  //That method will find for a label with stylename number and set the tag of component in it.
  inherited;
  if FindStyleResource<TLabel>('Number', NumberLabel) then
    NumberLabel.Text := IntToStr(Tag);
end;

      

Now set the style for all buttons. The text property will set the text alphanumeric text and the tag will set the number. It will only work at runtime.

+6


source







All Articles