Jump to content
ertank

FMX TListView Item color change runtime

Recommended Posts

Hello,

 

I want to conditionally change stock ImageListItemBottomDetail appearance TListViewItem (not the list but a single item) background color at runtime.

Stylebook - background changes for whole background as far as I can see.

 

Any help is appreciated.

 

Thanks & Regards,

Ertan

Share this post


Link to post
type
  TForm1 = class(TForm)
    ListView1: TListView;
    procedure FormCreate(Sender: TObject);
    procedure ListView1UpdateObjects(const Sender: TObject;
      const AItem: TListViewItem);
    procedure FormDestroy(Sender: TObject);
  private
    FCustomItem : TListViewItem;
    FBitmap     : TBitmap;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
begin
  for var i := 1 to 25 do
    ListView1.Items.Add.Text := Format('item #%u', [i]);

  FCustomItem := ListView1.Items[4];
  FCustomItem.Text := 'Custom Background Item';

  var c := TAlphaColorRec.Orangered;
  TAlphaColorRec(c).A := 64;

  FBitmap := TBitmap.Create(8, 8);
  FBitmap.Clear(c);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FBitmap.Free;
end;

procedure TForm1.ListView1UpdateObjects(const Sender: TObject;
  const AItem: TListViewItem);
begin
  if AItem = FCustomItem then
    begin
      var Bkgnd := TListItemImage.Create(nil);
      Bkgnd.ScalingMode := TImageScalingMode.Stretch;
      Bkgnd.OwnsBitmap := False;
      Bkgnd.Bitmap := FBitmap;

      AItem.View.Insert(0, Bkgnd);
    end;
end;

custom_bkgnd_item.png.b0d940ee2b3df6da645326e0cf0f5876.png

custom_bkgnd_item.zip

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×