我的 Activity 中有一个按钮。如果我点击显示 toast 。但是当我再次点击 Toast 时再次显示。所以结果当我点击很多次这个 Toast 会出现很长时间。当第一次消失时,接下来是显示等等。当我再次点击按钮时我该怎么做,第一个 toast 将被隐藏。
最佳答案
调用 cancel()
方法隐藏 Toast(如果已经显示)。
这可以简单地在 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/