public final class ToastUtil {
protected static Toast toast = null;
private static String oldMsg;
private static long time1=0;
private static long time2=0;
private static void showToast(Context context, String s){
if(toast==null){
toast =Toast.makeText(context, s, Toast.LENGTH_SHORT);
toast.show();
time1=System.currentTimeMillis();
}else{
time2=System.currentTimeMillis();
if(s.equals(oldMsg)){
if(time2-time1>300){
toast.show();
}
}else{
oldMsg = s;
toast.setText(s);
toast.show();
}
}
time1=time2;
}
/**
* 普通文本消息提示(短)
* @param context
* @param text
*/
public static void textToastShort(Context context,String text){
if (text == null) {
return;
}
showToast(context, text);
}
}
简单的全局Toast
最新推荐文章于 2022-04-14 22:11:54 发布