Android:Toast消息消失后​​如何关闭应用程序?

发布于 2024-12-08 13:26:59 字数 265 浏览 4 评论 0原文

正如标题所说。我试图在单击按钮时显示 Toast 文本,然后在消息消失后​​关闭应用程序。

Toast toast = Toast.makeText(getApplicationContext(), "Message here", Toast.LENGTH_SHORT);
toast.show();

finish();

这会在显示 toast 消息时关闭应用程序,我只是想知道是否可以将关闭应用程序延迟到消息消失后​​。

谢谢!

Just as the title says. I'm trying to have display a Toast text when a button is clicked, and then close the application after the message disappears.

Toast toast = Toast.makeText(getApplicationContext(), "Message here", Toast.LENGTH_SHORT);
toast.show();

finish();

This closes the application as the toast message displays and I was just wondering if I could delay closing the application to after the message disappears.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2024-12-15 13:26:59

您必须设置一个计时器来计时吐司消失的时间。
如果我没记错的话,LENGTH_SHORT 是 2 秒或左右。
调用带有计时器任务的计时器,延迟 2 秒,依次调用 finish。

You will have to set a timer for the time it takes the toast to disappear.
If I'm not mistaken, LENGTH_SHORT is 2 seconds or around it.
Call a timer with a timer task with a 2 seconds delay that will call finish in turn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文