android - toast 和持续时间

标签 android toast

我的 Activity 中有一个按钮。如果我点击显示 toast 。但是当我再次点击 Toast 时再次显示。所以结果当我点击很多次这个 Toast 会出现很长时间。当第一次消失时,接下来是显示等等。当我再次点击按钮时我该怎么做,第一个 toast 将被隐藏。

最佳答案

调用 cancel() 方法隐藏 Toast(如果已经显示)。

看看this API.

这可以简单地在 Toast 的对象上调用。

Toast toast = new Toast(context);

toast.setText("Text");
toast.show();//(call show()  to display Toast)
toast.cancel();//(call cancel() to  hide Toast).

关于android - toast 和持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10279004/

相关文章:

javascript - 我需要在 js 中创建我的 CSS 类的多个实例

java - contentView 不改变动态编程的内容。今天早上工作,我什至没有碰过它

android - 有时,当添加到处理程序内部时,Toast 在 Activity 或内部 fragment 中不可见

android - 按钮单击事件中的数据从一个 Activity 传输到另一个 Activity

android - 根据列表项更改上下文菜单文本

java - 将多个值传递给 Toast

java - Java 中的 Fading Indicator 消息

twitter-bootstrap - Bootstrap 4 snackbar / toast

java - 无法从上下文访问getContentResolver()?

android - 自动展开并关注 SearchView