杀死安卓吐司? [英] Kill android toast?

查看:35
本文介绍了杀死安卓吐司?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,在按钮上单击 Toast 出现,如果用户多次单击按钮并转到上一个活动甚至关闭应用程序 Toast 仍然可见,

I have a button and on button click toast appears, if the user clicks on button several times and go to previous activity or even close the aplication toast is still visible,

如何在用户进行任何其他活动时完成或取消 toast 或如何防止生成 toast?

How to finish or cancel the toast when user goes to any other activity or how to prevent generation of toast?

Toast.makeText(getApplicationContext(), "Enter correct goal!",
                        Toast.LENGTH_SHORT).show()

推荐答案

试试这个 cancel() Toast by using handler

try this cancel() Toast by using handler

Toast toast = Toast.makeText(getApplicationContext(), "Test", Toast.LENGTH_SHORT);

toast.show();

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
 @Override
 public void run() {
 toast.cancel(); 
 }
}, 500);

这篇关于杀死安卓吐司?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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