如何提前终止Toast消息?

时间:2012-09-29 10:48:59

标签: android toast

我有按钮点击时运行的Toast消息。我有另一个按钮,开始另一个活动。 如果用户正在进行该活动,则toast为Ok,但如果用户在Toast完成之前导航到新活动,则显示它并不合适。如何在活动结束后立即结束祝酒。

1 个答案:

答案 0 :(得分:1)

Close the view if it's showing, or don't show it if it isn't showing yet. You do not normally have to call this. Normally view will disappear on its own after the appropriate duration.

我没试过这个......希望它会起作用..

  toast.cancel(); 

修改

Toast t = new Toast(mContext);
t=Toast.makeText(mContext,"text", Toast.LENGTH_SHORT); 
t.show(); 

并在任何地方使用t.cancel();