Toast工具类,解决一直谈吐司问题

来源:互联网 发布:abigail mac 编辑:程序博客网 时间:2024/05/16 09:45

如果吐司一直弹出,是不是很无奈,想砸了吐司?

那么解决方案来了,如下代码……


public class ToastUtils {    private static Toast TOAST;    private static final String TAG = "ToastUtil";    //短时间吐司    public static void show(Context context, int resourceID) {        show(context, resourceID, Toast.LENGTH_SHORT);    }    //短时间吐司    public static void show(Context context, String text) {        show(context, text, Toast.LENGTH_SHORT);    }    //自定义时长吐司    public static void show(Context context, Integer resourceID, int duration) {        String text = context.getResources().getString(resourceID);// 用于显示的文字        show(context, text, duration);    }    //自定义时长吐司    public static void show(final Context context, final String text, final int duration) {        if (TOAST == null) {            TOAST = Toast.makeText(context, text, duration);        } else {            TOAST.setText(text);            TOAST.setDuration(duration);        }        TOAST.show();    }}


1 0