在代码中,如果toast连续进行会非常的恶心人,那么就对toast进行封装,以后就使用这个toast
/**
* Created by along on 2017/12/1,0001.
* 邮箱:alongstorm@163.com
*/
public class ToastUtils {
private static Context context = MyApp.getAppContext();
private static Toast toast;
public static void show(int resId) {
show(context.getResources().getText(resId), Toast.LENGTH_SHORT);
}
public static void show(int resId, int duration) {
show(context.getResources().getText(resId), duration);
}
public static void show(CharSequence text) {
show(text, Toast.LENGTH_SHORT);
}
/*public static void showDebug(CharSequence text) {
if (BuildConfig.DEBUG) {
show(text, Toast.LENGTH_SHORT);
}
}*/
public static void show(CharSequence text, int duration) {
text = TextUtils.isEmpty(text == null ? "" : text.toString()) ? "请检查您的网络!" : text;
if (toast == null) {
toast = Toast.makeText(context, text, duration);
} else {
toast.setText(text);
}
toast.show();
}
public static void show(int resId, Object... args) {
show(String.format(context.getResources().getString(resId), args),
Toast.LENGTH_SHORT);
}
public static void show(String format, Object... args) {
show(String.format(format, args), Toast.LENGTH_SHORT);
}
public static void show(int resId, int duration, Object... args) {
show(String.format(context.getResources().getString(resId), args),
duration);
}
public static void show(String format, int duration, Object... args) {
show(String.format(format, args), duration);
}
}
使用起来那是相当的得劲啊