您可以添加一个帮助程序以在 TCustomListView 中设置私有变量,
尽管由于某种原因,它仅在您添加了一些项目后才有效
unit ListViewHelper;
interface
uses FMX.ListView, System.UITypes ;
type
TListViewHelper = class helper for TCustomListView
procedure SetItemStyleFillColour(Colour : TAlphaColor);
procedure SetBackgroundStyleColor(Colour : TAlphaColor);
end;
implementation
{ TListViewHelper }
procedure TListViewHelper.SetBackgroundStyleColor(Colour: TAlphaColor);
begin
TCustomListView(self).FBackgroundStyleColor := Colour;
end;
procedure TListViewHelper.SetItemStyleFillColour(Colour: TAlphaColor);
begin
TCustomListView(self).FItemStyleFillColor := Colour;
end;
end.
然后在要更改背景颜色的任何地方使用该单元并调用 SetItemStyleFillColour
lv1.SetItemStyleFillColour(TAlphaColor($FF4A494A));
lv1.SetBackgroundStyleColor(TAlphaColorRec.Blue);
例如
unit Main;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.ListView.Types, FMX.ListView;
type
TForm1 = class(TForm)
lv1: TListView;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ListViewHelper;
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
begin
lv1.Items.Add.Text := FormatDateTime('dd-mm-yyyy HH:NN:SS ZZZ', Now());
lv1.Items.Add.Text := FormatDateTime('dd-mm-yyyy HH:NN:SS ZZZ', Now());
lv1.SetItemStyleFillColour(TAlphaColor($FF4A494A));
lv1.SetBackgroundStyleColor( TAlphaColorRec.Blue);
end;
end.