Creating a custom custom TListBoxItem with this example and problems with the fontColor property

enter image description here
Can someone please direct me in the right direction. I am trying to create a custom ListboxItem using Delphi XE4 for an iOS application. The output of my target will be something like the line above where I am stuck right now (image below).

enter image description here

I managed to dynamically generate a ListBoxItem and insert a TLabel object, however I cannot change the fontColor TLabel property to the desired color. I can encode

TLabel.Fontcolor: = ClaBlue;

But the color goes back to black. I would ideally want it to look the same as the example I am giving. I'm having problems changing the font color of the inserted TLabel and adding a gradient background to each list item. I do not know if I need to use the "style editor" or even how. And yes, I looked at the sample included in Delphi / RAD Studio. Here is my current encoding below:

while XMLNode<>nil do begin HeaderText := 'Part#: ' + XMLNode.ChildNodes['PARTNUM'].Text + Chr(9) + XMLNode.ChildNodes['VENDPARTNUM'].Text; DetailText := '$' + XMLNode.ChildNodes['MD1_SELL_PRICE'].Text + ' /' + XMLNode.ChildNodes['UM1_PRICE_NAME'].Text + sLineBreak + 'Min: ' + XMLNode.ChildNodes['md2_from.MD2_MIN_QTY'].text + Chr(9) + 'On Hand: ' + XMLNode.ChildNodes['md2_from.MD2_ON_HAND_QTY'].text + Chr(9) + Label1.text ; Form6.ListBox1.Items.Add(DetailText); ListBoxItem:=Form6.ListBox1.ListItems[Form6.ListBox1.Items.Count-1]; ListBoxItem.StyleLookup:='listboxitembottomdetail'; ListBoxItem.WordWrap:=True; ListBoxItem.Font.Size:= 8; ListBoxItem.Height := 120; TestLabel := TLabel.Create(self); TestLabel.Text := HeaderText; TestLabel.font.size := 20; testLabel.FontColor := claBlue; TestLabel.Width := form6.ListBox1.ClientWidth; i := i +1; XMLNode := XMLNode.NextSibling; end; Form6.ListBox1.EndUpdate; Form6.Show; 
+4
source share
1 answer

You must use the Stylebook, use the CustomListBox sample that comes with delphi to learn how to use styles in Firemonkey correctly.

It would also be nice to read some official Firemonkey style guides for implementation, such as Customizing FireMonkey apps with styles .

It looks more complex than possible, in short to get the result you want:

  • Access to component style constructor
  • Through the structure window, edit / add / delete and change the controls, in your case it will be a combination of TText Controls organized in Tlayouts .
  • After saving changes, you can change the color of a specific TText control at run time: Item.StylesData['TestLabel.Color'] := TAlphaColors.Red; (where Item is a TListboxitem)

What you are trying to achieve is not difficult, to learn how to deal with Style Designer through practice, pure trial and error, it is not as difficult as it seems.

+1
source

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


All Articles