Android toast 出现在每个选项卡中
我目前有一个选项卡视图,在我的第一个选项卡中出现一条吐司消息。如果在 Toast 仍在显示时单击另一个选项卡,它也会显示在该选项卡中。有什么办法可以不让这种情况发生吗?我是否只需在 onPause()
内取消它?感谢您的帮助
I currently have a tabview and in my first tab i have a toast message that appears. If click on another tab while the toast is still displaying, it will display in that tab as well. Is there any way to not make this happen? Do i simply cancel it inside the onPause()
? thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以检测选项卡更改并在该方法中取消它。有关选项卡更改帮助 - Android TabWidget 检测点击当前选项卡
You could detect tab change and cancel it in that method. For tab change help - Android TabWidget detect click on current tab
Toast 不与任何特定活动绑定,因为它们覆盖在屏幕上。如果您想显式关闭 Toast,则需要将其句柄传递给需要关闭它的 Activity 并调用 Toast.cancel()。
Toast's are not tied with any particular activity as they are an overlay over the screen. If you want to explicitly close the Toast, you need to pass a handle of it to whichever activity needs to close it and call
Toast.cancel()
.是的,您可以简单地在创建它的活动的
onPause()
中调用cancel()
。Yeah you can simply call
cancel()
inonPause()
of the activity that has created it.