Delphi XE8 Firemonkey TListView-如何以编程方式设置背景色
TListView与样式相连接。此样式包含名为background的TColorObject。如果您在样式设计器中设置了TColorObject.Color(红色),Treeview将显示此颜色。 如果在TListView的ApplyStyleLookup事件中以编程方式设置颜色,则背景色仍保留在样式中设置的颜色(红色)Delphi XE8 Firemonkey TListView-如何以编程方式设置背景色,delphi,firemonkey,delphi-xe8,tlistview,Delphi,Firemonkey,Delphi Xe8,Tlistview,TListView与样式相连接。此样式包含名为background的TColorObject。如果您在样式设计器中设置了TColorObject.Color(红色),Treeview将显示此颜色。 如果在TListView的ApplyStyleLookup事件中以编程方式设置颜色,则背景色仍保留在样式中设置的颜色(红色) procedure TTest.TreeViewlistApplyStyleLookup(Sender: TObject); var co: TColorObject; be
procedure TTest.TreeViewlistApplyStyleLookup(Sender: TObject);
var
co: TColorObject;
begin
co := nil;
if Sender is TListView then co := TListView(Sender).FindStyleResource('background') as TColorObject;
if co <> nil then co.Color := TAlphaColors.Black;
//co is not nil
//TColorObject background is found and black is set, but it remains on red
end;
过程TTest.TreeViewlistApplyStyleLookup(发送方:ToObject);
变量
co:TColorObject;
开始
co:=零;
如果发送方是TListView,则co:=TListView(发送方)。FindStyleResource('background')作为TclorObject;
如果co为零,则co.颜色:=TAlphaColors.黑色;
//co不是零
//t找到彩色对象背景并设置为黑色,但仍保持为红色
结束;
您可以将TListView放在TRectangle中,并将listview的透明属性设置为True。您可以添加一个帮助程序来设置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.
然后在任何需要更改背景颜色的地方使用该单元,并调用SetItemStyleFillColor1级。SetItemStyleFillColor(TAlphaColor($FF4A494A))
lv1.SetBackgroundStyleColor(TAlphaColorRec.蓝色) e、 g
如果我设置了透明度,ListViewItem也不可见,但我认为如果我将样式中的背景色设置为透明色,它可能会起作用,但结果是,如果TListView可以应用仅在设计器中可更改的样式。这在Delphi Seattle+上不再起作用,因为这两个变量现在都是私有的。
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.