连续弹出Toast时,系统会默认一个个弹出,会造成触发了之后很久才会有这个Toast的出现。下边的代码可以解决这个问题:
public class ToastUtil {
private static Toast toast;
public static void show(String text) {
if (toast != null) {
toast.cancel();
}
toast = Toast.makeText(App.getContext(), text, Toast.LENGTH_SHORT);
toast.show();
}
public static void showLong(String text) {
if (toast != null) {
toast.cancel();
}
toast = Toast.makeText(App.getContext(), text, Toast.LENGTH_LONG);
toast.show();
}
}
网友评论