Android 取消 上一个Toast

如果你使用
Toast.makeText(MainActivity.this, "test", Toast.LENGTH_SHORT).show();

这种方法连续弹Toast的话,那简直是煎熬啊!

所以你要连续弹的话,这样写

Toast toast;
        if(toast==null){
            toast = Toast.makeText(this, "test", Toast.LENGTH_SHORT);
        }else{
            toast.setText("test");
        }
        toast.show();

然后你要马上取消Toast的话(比如退出应用的时候),这样

toast.cancel();

你可能感兴趣的:(Android)