admin
2021-05-17 06a80d5c4b3a971cdc1ca3d91717ec3f6e03a443
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.tejia.lijin.app.util;
 
import android.content.Context;
import android.widget.Toast;
 
public class ToastUtil {
    private static String oldMsg;
    protected static Toast toast = null;
    private static long oneTime = 0;
    private static long twoTime = 0;
 
    public static void showSingleToast(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 > 2000) {
                    toast = Toast.makeText(context, s, Toast.LENGTH_SHORT);
                    toast.show();
                    oneTime = twoTime;
                }
            } else {
                oldMsg = s;
                toast.setText(s);
                toast.show();
            }
        }
 
    }
 
 
    public static void showToast(Context context, int resId) {
        showSingleToast(context, context.getString(resId));
    }
 
}