针对以前的单利toast,先上最早的单利吐司
不能用,不能用,不能用
public static void show(Context context, String msg) {
if (toast == null) {
toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
} else {
toast.setText(msg);
}
toast.show();
}
现在这种形式不行了,还是断断续续的显示
public static void show(Context context, String msg) {
if (toast == null) {
toast.cancel()
}
toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
toast.show();
}
或者是
//其实上下文可以封装的,自定义显示Toast,这个可以自定义
public static void show(String msg) {
if (view==null) { inflater = LayoutInflater .from(AppComplication.mContext); view = inflater.inflate(R.layout.toast_layout, null); mTextView = (TextView) view.findViewById(R.id.toast_text); } if (toast == null) { toast = new Toast(AppComplication.mContext); mTextView.setText(msg); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(view); toast.show(); }else { toast.cancel(); toast = new Toast(AppComplication.mContext); mTextView.setText(msg); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(view); toast.show(); }
}