简体   繁体   English

为 FMX 弹出窗口设置背景 window

[英]Set background for FMX popup window

I have an FMX Android project compiled with Delphi 10.1 Berlin.我有一个用 Delphi 10.1 Berlin 编译的 FMX Android 项目。 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.用户需要 select 从 19 个值来运行它,我使用 TPopupBox 组件显示 19 个 TRadioButtons,这些按钮显示在 3 列 7+7+5 按钮中用于该选择。

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.默认为透明弹出窗口 window,这是无用的,因此我编辑样式以将白色 TRectangle 添加到弹出窗口 window 的背景,但前提是我调整矩形大小以匹配弹出窗口的大小。 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?我如何自动调整矩形的大小而不是在设计时修复它以匹配我为 popup.bounds 设置的计算值?
  2. Is adding a TRectangle to the style background the best way to get an opaque control?将 TRectangle 添加到样式背景是获得不透明控件的最佳方式吗?

I have tried all obvious align options and searched the inte.net.我已经尝试了所有明显的对齐选项并搜索了 inte.net。 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.其他人建议编辑清单,但我的清单在编译时被覆盖。

I believe you wrote erroneously TPopupBox and probably meant to write TPopup .我相信您错误地写了TPopupBox并且可能打算写TPopup That is anyway what you should use for popup windows.无论如何,这就是您应该用于弹出窗口 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.这将显示和隐藏弹出窗口 window。

Add a TPopup and size it as you wish, and set Visible:= True .添加一个TPopup并根据需要调整大小,然后设置Visible:= True

Add a rectangle inside the popup and set its Align property to Contents .在弹出窗口中添加一个矩形并将其Align属性设置为Contents Set its Fill.Color property as you wish.根据需要设置其Fill.Color属性。 Add TRadiobuttons as you wish, on the rectangle.根据需要在矩形上添加TRadiobuttons

Finally, the code to toggle the popup visibility (but see notes in Help ):最后,切换弹出窗口可见性的代码(但请参阅 Help 中的注释):

Popup1.IsOpen := not Popup1.IsOpen;

Please note!请注意! There are many properties that jointly affect the placement of the TPopup : Placement , PlacementRectangle , PlacementTarget .有许多属性共同影响TPopup的放置: PlacementPlacementRectanglePlacementTarget As I don't know your needs, I leave it to you to decide what to use.由于我不知道您的需求,因此请您自行决定使用什么。

A sample test case:示例测试用例:

在此处输入图像描述

Here PlacementTarget is Button1 and Placement is Bottom .这里的PlacementTargetButton1PlacementBottom

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM