Android-隐藏所有显示的Toast消息 [英] Android - Hide all shown Toast Messages

查看:279
本文介绍了Android-隐藏所有显示的Toast消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除当前显示的所有吐司消息?

How do I remove all toast messages currently displayed?

在我的应用程序中,有一个列表,当用户单击某个项目时,会显示一条敬酒消息, 10条-10条吐司消息.

In my App, there is a list, when a user clicks on an item, a toast message is displayed, 10 items - 10 toast messages.

因此,如果用户单击10次,然后按菜单按钮,则他们必须等待几秒钟才能读取菜单选项文本.

So if the user clicks 10 times, then presses the menu button, they have to wait for some seconds until they're able to read the menu option text.

不应该这样:)

推荐答案

我的解决方案是在活动中初始化一个Toast.然后在每次点击时更改其文字.

My solution was to initialize a single Toast in the activity. Then changing its text on each click.

Toast mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
if (a) {
  mToast.setText("This is a");
  mToast.show();
} else if (b) {
  mToast.setText("This is b");
  mToast.show();
}

这篇关于Android-隐藏所有显示的Toast消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆