当前位置 : 主页 > 编程语言 > java >

工具类ToastManager

来源:互联网 收集:自由互联 发布时间:2021-06-28
工具类ToastManager import android.content.Context;import android.widget.Toast;/** * 吐司管理类 */public class ToastManager {private static String oldMsg;protected static Toast toast = null;private static long oneTime = 0;private sta
工具类ToastManager
import android.content.Context;
import android.widget.Toast;

/**
 *  吐司管理类
 */
public class ToastManager {

	private static String oldMsg;
	protected static Toast toast = null;
	private static long oneTime = 0;
	private static long twoTime = 0;

	public static void showToast(Context context, String s) {

		if (toast == null) {
			toast = Toast.makeText(context, s, Toast.LENGTH_SHORT);
			toast.show();
			oneTime = System.currentTimeMillis();
		} else {
			twoTime = System.currentTimeMillis();
			if (s.equals(oldMsg)) {
				if (twoTime - oneTime > Toast.LENGTH_SHORT) {
					toast.show();
				}
			} else {
				oldMsg = s;
				toast.setText(s);
				toast.show();
			}
		}
		oneTime = twoTime;
	}
}
网友评论