android不重复弹出的Toast
作者:
网瘾青年 | 来源:发表于
2017-09-15 12:22 被阅读0次public class ToastUtil {
private static WeakReference<Toast> sToast;
public static void show(CharSequence content) {
if (TextUtils.isEmpty(content)) {
return;
}
if (sToast != null && sToast.get() != null) {
sToast.get().setText(content);
sToast.get().show();
} else {
Toast toast = Toast.makeText(MyApplication.getApp(), content, Toast.LENGTH_SHORT);
sToast = new WeakReference<>(toast);
toast.show();
}
}
public static void cancel() {
if (sToast != null && sToast.get() != null) {
sToast.get().cancel();
}
}
}
本文标题:android不重复弹出的Toast
本文链接:https://www.haomeiwen.com/subject/ecjssxtx.html
网友评论