ToastUtil.java
2.98 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
package com.sunvote.util;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;
/**
* Created by Elvis on 2017/8/15 15:03
* Email:Eluis@psunsky.com
* 版权所有:长沙中天电子设计开发有限公司
* Description: 工具包
*/
public class ToastUtil {
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param resId 资源id
*/
public static void show(Context context, int resId) {
show(context, context.getResources().getText(resId), Toast.LENGTH_SHORT);
}
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param resId 资源id
* @param duration 显示时长
*/
public static void show(Context context, int resId, int duration) {
show(context, context.getResources().getText(resId), duration);
}
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param text 消息内容
*/
public static void show(Context context, CharSequence text) {
show(context, text, Toast.LENGTH_SHORT);
}
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param text 消息内容
* @param duration 显示时长
*/
public static void show(Context context, CharSequence text, int duration) {
text = TextUtils.isEmpty(text == null ? "" : text.toString()) ? "请检查您的网络!"
: text;
Toast mToast = Toast.makeText(context, text, duration);
mToast.show();
}
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param resId 资源id
* @param args 资源id对应的字符串的占位符的内容
*/
public static void show(Context context, int resId, Object... args) {
show(context, String.format(context.getResources().getString(resId), args),
Toast.LENGTH_SHORT);
}
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param format 消息内容
* @param args 上下文
*/
public static void show(Context context, String format, Object... args) {
show(context, String.format(format, args), Toast.LENGTH_SHORT);
}
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param resId 资源id
* @param duration 时长
* @param args 资源id对应的字符串的占位符的内容
*/
public static void show(Context context, int resId, int duration, Object... args) {
show(context, String.format(context.getResources().getString(resId), args),
duration);
}
/**
* 展示给用户的Toast信息
* @param context 上下文
* @param format 消息内容
* @param duration 时长
* @param args 资源id对应的字符串的占位符的内容
*/
public static void show(Context context, String format, int duration, Object... args) {
show(context, String.format(format, args), duration);
}
}