简单的全局Toast

来源:互联网 发布:99家居软件 编辑:程序博客网 时间:2024/05/21 08:41
public final class ToastUtil {    protected static Toast toast   = null;    private static String oldMsg;    private static long time1=0;    private static long time2=0;    private static void showToast(Context context, String s){        if(toast==null){            toast =Toast.makeText(context, s, Toast.LENGTH_SHORT);            toast.show();            time1=System.currentTimeMillis();        }else{            time2=System.currentTimeMillis();            if(s.equals(oldMsg)){                if(time2-time1>300){                    toast.show();                }            }else{                oldMsg = s;                toast.setText(s);                toast.show();            }        }        time1=time2;    }    /**     * 普通文本消息提示(短)     * @param context     * @param text     */    public static void textToastShort(Context context,String text){        if (text == null) {            return;        }        showToast(context, text);    }}
0 0