51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

How to close TDialogService.MessageDialog() automatically after a certain time in Delphi FMX on Android?

英文:

How to close TDialogService.MessageDialog() automatically after a certain time in Delphi FMX on Android?

问题 {#heading}

我在Delphi FMX上的Android平台上有以下代码:

````delphi
TDialogService.MessageDialog('测试关闭消息', TMsgDlgType.mtInformation,
                  [TMsgDlgBtn.mbOK], TMsgDlgBtn.mbOK, 0, nil);
</code></pre>
 <p>我需要在3秒后自动关闭<code>TDialogService.MessageDialog</code>。</p>
 <p>我尝试了<code>Screen.MousePos.SetLocation(x, x)</code>来模拟点击。</p>
 <pre><code>
&lt;details&gt;
&lt;summary&gt;英文:&lt;/summary&gt;

I have the following code in Delphi FMX on Android:

```delphi
TDialogService.MessageDialog(&amp;#39;Test Close message&amp;#39;, TMsgDlgType.mtInformation,
                  [TMsgDlgBtn.mbOK], TMsgDlgBtn.mbOK, 0, nil);
</code></pre>
 <p>I need to auto-close <code>TDialogService.MessageDialog</code> after 3 seconds.</p>
 <p>I tried <code>Screen.MousePos.SetLocation(x, x)</code> for set a tap to simulate.</p>
 <h1 id="1">答案1</h1>
 <p><strong>得分</strong>: 2</p>
 <p>在Android上,<code>TDialogService.MessageDialog()</code> 简单地调用 <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.IFMXDialogServiceAsync.MessageDialogAsync"><code>IFMXDialogServiceAsync.MessageDialogAsync()</code></a>(因为Android不支持同步对话框)。 默认实现位于 <code>FMX.Dialogs.Android</code> 单元中的 <code>TFMXDialogService</code> 类中。</p>
 <p>您无法访问它创建的UI对话框,因此无法手动关闭它。 但是,您可以编写自己的类,实现 <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.IFMXDialogServiceAsync"><code>IFMXDialogServiceAsync</code></a> 接口,然后 <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.TPlatformServices.AddPlatformService" rel="external nofollow" target="_blank">将该类注册到FMX</a>(您需要首先 <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.TPlatformServices.RemovePlatformService" rel="external nofollow" target="_blank">删除默认服务</a>)。 然后,您可以对您的对话框实现执行任何操作。 例如,您可以显示自己的带有计时器的窗体以关闭窗体。</p>
 <details>
  <summary>英文:</summary>
  <p>On Android, <code>TDialogService.MessageDialog()</code> simply calls <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.IFMXDialogServiceAsync.MessageDialogAsync"><code>IFMXDialogServiceAsync.MessageDialogAsync()</code></a> (as Android does not support synchronous dialogs). The default implementation is buried in the <code>TFMXDialogService</code> class in the <code>FMX.Dialogs.Android</code> unit.</p>
  <p>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 <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.IFMXDialogServiceAsync"><code>IFMXDialogServiceAsync</code></a> interface, and then <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.TPlatformServices.AddPlatformService" rel="external nofollow" target="_blank">register that class with FMX</a> (you will have to <a href="https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.TPlatformServices.RemovePlatformService" rel="external nofollow" target="_blank">remove the default service</a> 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.</p>
 </details>
 <p></p>
</div>

````


赞(1)
未经允许不得转载:工具盒子 » How to close TDialogService.MessageDialog() automatically after a certain time in Delphi FMX on Android?