吐司工具类--ToastUtil

来源:互联网 发布:完美芦荟胶淘宝正品店 编辑:程序博客网 时间:2024/04/27 14:26
/** * Created by peng on 2015/6/15. * 吐司工具类 */public class ToastUtil {    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(@NonNull final Context context, @NonNull final String text, final int duration) {            if (TOAST == null) {                TOAST = Toast.makeText(context, text, duration);            } else {                TOAST.setText(text);                TOAST.setDuration(duration);            }            TOAST.show();    }}
0 0
原创粉丝点击