Toast的封装

来源:互联网 发布:反网络爬虫 编辑:程序博客网 时间:2024/06/05 11:22

博客转载:http://blog.csdn.net/guolin_blog/article/details/51336415
本文出自郭霖的博客

这是从牛人的博客中看到的,基本上的思路就是当多次点击一个按钮,如何去屏蔽若此弹出提示的问题
直接上代码:

public class Utils {    private static Toast toast;    public static void showToast(Context context, String content) {        if (toast == null) {            toast = Toast.makeText(context, content, Toast.LENGTH_SHORT);        } else {            toast.setText(content);        }        //显示        toast.show();    }}

这里我们封装了一个类,也就是说,当Toast实例不为空的时候,我直接设置提示信息。
这就是简单而又有用的技巧

0 0