ToastUtils工具类

来源:互联网 发布:python bloomfilter 编辑:程序博客网 时间:2024/06/06 19:03

防止用户快速操作导致Toast多次显示

import android.content.Context;import android.widget.Toast;/** * 自定义Toast工具类,防止用户快速操作导致Dialog多次显示 */public class CustomToast {    private static Toast mToast;    public static void showToast(Context mContext, String text, int duration) {        if (mToast != null) {            mToast.setText(text);        } else {            mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);        }        mToast.show();    }    public static void showToast(Context mContext, int resId, int duration) {        showToast(mContext, mContext.getResources().getString(resId), duration);    }}
原创粉丝点击