Lorne Anderson
Lorne Anderson

Reputation: 47

Set background for FMX popup window

I have an FMX Android project compiled with Delphi 10.1 Berlin. The user needs to select from 19 values to run it and I use a TPopupBox component to display 19 TRadioButtons that show in 3 columns of 7+7+5 buttons for that selection.

The default is for a transparent popup window which is useless, so I edited the style to add a white TRectangle to the background of the popup window which works, but only if I size the rectangle to match the size of the popup. Aligning the rectangle to client or contents only sets an opaque background to the first row of radio buttons. I have 2 questions:

  1. How can I auto size the rectangle rather than fixing it at design time to match what I calculate will be set for popup.bounds?
  2. Is adding a TRectangle to the style background the best way to get an opaque control?

I have tried all obvious align options and searched the internet. Somebody suggested deleting 'background' from the style list but that did not work. Somebody else suggested editing the manifest but my manifest just gets overwritten when I compile.

Upvotes: 0

Views: 313

Answers (1)

Tom Brunberg
Tom Brunberg

Reputation: 21045

I believe you wrote erroneously TPopupBox and probably meant to write TPopup. That is anyway what you should use for popup windows.

You may want to create a new project, for testing purposes. Add a button near top left. This will show and hide the popup window.

Add a TPopup and size it as you wish, and set Visible := True.

Add a rectangle inside the popup and set its Align property to Contents. Set its Fill.Color property as you wish. Add TRadiobuttons as you wish, on the rectangle.

Finally, the code to toggle the popup visibility (but see notes in Help):

Popup1.IsOpen := not Popup1.IsOpen;

Please note! There are many properties that jointly affect the placement of the TPopup: Placement, PlacementRectangle, PlacementTarget. As I don't know your needs, I leave it to you to decide what to use.

A sample test case:

enter image description here

Here PlacementTarget is Button1 and Placement is Bottom.

Upvotes: 1

Related Questions