Android简单的Toast工具类

来源:互联网 发布:程序员图片 编辑:程序博客网 时间:2024/06/05 11:44

写了一个简单的工具类ToastUtil

public class ToastUtil {    private static Toast toast;    /**     * @param context     * @param stringId     */    public static void showShortToast(Context context, int stringId) {        if (toast != null) {            toast.cancel();        }        Toast.makeText(context, stringId, Toast.LENGTH_SHORT).show();    }    /**     * @param context     * @param stringId     */    public static void showLongToast(Context context, int stringId) {        if (toast != null) {            toast.cancel();        }        Toast.makeText(context, stringId, Toast.LENGTH_LONG).show();    }    /**     * @param context     * @param stringId     */    public static void showToast(Context context, int stringId) {        if (toast == null) {            toast = Toast.makeText(context, stringId, Toast.LENGTH_SHORT);        } else {            toast.setText(stringId);        }        toast.show();    }}

也可以直接修改形参,为要提示的String语句。



0 0
原创粉丝点击