Android常用工具类4(防止连续点击多次,Toast长时间显示的问题)

xiaoxiao2021-02-28  138

package zz; import android.widget.Toast; /** * @author zz * @describe 自定义Toast,防止连续点击多次,Toast长时间显示的问题 **/ public class ToastUtils { private static String oldMsg; protected static Toast toast = null; private static long oneTime = 0; private static long twoTime = 0; public static void showToast(String s) { if (toast == null) { toast = Toast.makeText(ConstantUtils.mContext, 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; } }

 

转载请注明原文地址: https://www.6miu.com/read-27805.html

最新回复(0)