美文网首页Android知识
android不重复弹出的Toast

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