1

TListView 与样式相连。此样式包含一个名为 background 的 TColorObject。如果您在 styledesigner 中设置 TColorObject.Color(红色),Treeview 将显示此颜色。如果在 TListView 的 ApplyStyleLookup 事件中以编程方式设置颜色,则背景颜色保持在样式中设置的颜色(红色)上!!!

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;
4

3 回答 3

2

您可以添加一个帮助程序以在 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.
于 2015-08-28T03:13:17.833 回答
1

您可以将TListView 放在TRectangle 上,并将listview 的Transparent 属性设置为True。

于 2015-08-26T15:11:20.373 回答
0
use System.Rtti; 

TRttiContext.Create.GetType(TListView).GetField('FBackgroundStyleColor').SetValue(ListView2, TAlphaColorRec.Orange);

TRttiContext.Create.GetType(TListView).GetField('FItemStyleFillColor').SetValue(ListView2, TAlphaColorRec.Azure);
于 2021-11-04T23:27:26.920 回答