public class ToastUtils {
private static Toast mToast;
public static void showToastShort(Context context, String msg) {
if (mToast == null) {
if (msg != null && msg.length() > 13) {
mToast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
} else {
mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
}
mToast.setGravity(Gravity.CENTER, 0, 0);
} else {
mToast.setText(msg);
}
mToast.show();
}
/**
* Activity销毁时在onDestory中调用
* 即可修复APP退出时仍显示toast的问题
*/
public static void cancleToast() {
if (mToast != null) {
mToast.cancel();
}
}
}