英文:
How to close TDialogService.MessageDialog() automatically after a certain time in Delphi FMX on Android?
问题
我在Delphi FMX上的Android平台上有以下代码:
```delphi
TDialogService.MessageDialog('测试关闭消息', TMsgDlgType.mtInformation,
[TMsgDlgBtn.mbOK], TMsgDlgBtn.mbOK, 0, nil);
我需要在3秒后自动关闭TDialogService.MessageDialog
。
我尝试了Screen.MousePos.SetLocation(x, x)
来模拟点击。
<details>
<summary>英文:</summary>
I have the following code in Delphi FMX on Android:
```delphi
TDialogService.MessageDialog('Test Close message', TMsgDlgType.mtInformation,
[TMsgDlgBtn.mbOK], TMsgDlgBtn.mbOK, 0, nil);
I need to auto-close TDialogService.MessageDialog
after 3 seconds.
I tried Screen.MousePos.SetLocation(x, x)
for set a tap to simulate.
答案1
得分: 2
在Android上,TDialogService.MessageDialog()
简单地调用 IFMXDialogServiceAsync.MessageDialogAsync()
(因为Android不支持同步对话框)。 默认实现位于 FMX.Dialogs.Android
单元中的 TFMXDialogService
类中。
您无法访问它创建的UI对话框,因此无法手动关闭它。 但是,您可以编写自己的类,实现 IFMXDialogServiceAsync
接口,然后 将该类注册到FMX(您需要首先 删除默认服务)。 然后,您可以对您的对话框实现执行任何操作。 例如,您可以显示自己的带有计时器的窗体以关闭窗体。
英文:
On Android, TDialogService.MessageDialog()
simply calls IFMXDialogServiceAsync.MessageDialogAsync()
(as Android does not support synchronous dialogs). The default implementation is buried in the TFMXDialogService
class in the FMX.Dialogs.Android
unit.
You don't have access to the UI dialog it creates, so you can't close it manually. But, what you could do is write your own class that implements the IFMXDialogServiceAsync
interface, and then register that class with FMX (you will have to remove the default service first). Then, you can do whatever you want with your dialog implementation. For instance, you could display your own Form that has a timer on it to close the Form.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论