ToastUtil.java
4.27 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.glsx.commonres.util;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.Toast;
import com.glsx.commonres.CommonResApp;
import com.blankj.utilcode.util.ToastUtils;
/**
* Author by zh, Date on 2022/3/2.
* PS: write a bug or more,please indicate.
* Toast工具类
*/
public class ToastUtil {
private static Toast lastToast = null;
public final static int LENGTH_SHORT = Toast.LENGTH_SHORT;
public final static int LENGTH_LONG = Toast.LENGTH_LONG;
public static void clear() {
if (lastToast != null) {
lastToast.cancel();
}
}
public static void show(int i) {
// show(CommonResApp.getContext(), i);
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setDurationIsLong(false);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(i);
}
public static void show(Context context, int i) {
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setDurationIsLong(false);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(i);
// show(context, context.getString(i), LENGTH_SHORT);
}
public static void showLongText( int i) {
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setDurationIsLong(true);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(i);
// Context context = CommonResApp.getContext();
// show(context, context.getString(i), Toast.LENGTH_LONG);
}
public static void showLongText( CharSequence charsequence) {
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setDurationIsLong(true);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(charsequence);
// Context context = CommonResApp.getContext();
// show(context, charsequence, Toast.LENGTH_LONG);
}
public static void show(Context context, CharSequence charsequence) {
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setDurationIsLong(true);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(charsequence);
// show(context, charsequence, LENGTH_SHORT);
}
public static void show(CharSequence charsequence) {
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setDurationIsLong(false);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(charsequence);
// show(CommonResApp.getContext(), charsequence);
}
public static void showCenterTop(int msg) {
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setGravity(Gravity.CENTER, 0, -300);
toastUtils.setDurationIsLong(false);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(msg);
// if (lastToast != null)
// lastToast.cancel();
// Context context = CommonResApp.getContext();
// Toast toast = Toast.makeText(context, context.getString(msg), LENGTH_SHORT);
// lastToast = toast;
// toast.setGravity(Gravity.CENTER, 0, -300);
// toast.show();
}
public static void showCenterTop(String msg) {
ToastUtils toastUtils = ToastUtils.make();
toastUtils.setGravity(Gravity.CENTER, 0, -300);
toastUtils.setDurationIsLong(false);
toastUtils.setBgColor(Color.BLACK);
toastUtils.setTextColor(Color.WHITE);
toastUtils.show(msg);
// if (lastToast != null)
// lastToast.cancel();
// Context context = CommonResApp.getContext();
// Toast toast = Toast.makeText(context, msg, LENGTH_SHORT);
// lastToast = toast;
// toast.setGravity(Gravity.CENTER, 0, -300);
// toast.show();
}
private static final boolean isShow = false;
/**
* 调试使用
*
* @param charsequence
*/
public static void showTest(CharSequence charsequence) {
if (isShow)
Toast.makeText(CommonResApp.getContext(), charsequence, Toast.LENGTH_SHORT).show();
}
}