您的位置:首页 > 其它

ToastUtil,一个简单的Toast封装

2016-06-21 00:00 232 查看
import android.widget.Toast;

public class ToastUtil {
private static Toast mToast = null;

private static long lastClickTime;

// 防止连续点击按钮
public synchronized static boolean isFastClick() {
long time = System.currentTimeMillis();
if (time - lastClickTime < 1900) {
return true;
}
lastClickTime = time;
return false;
}

static {
mToast = Toast.makeText(context, "",
Toast.LENGTH_SHORT);
}

public static void showToast(String str) {
try {
mToast.setText(str);
mToast.show();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void showToast(int resId) {
try {
mToast.setText(resId);
mToast.show();
} catch (Exception e) {
e.printStackTrace();
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: