一、连续点击Toast不显示问题
在Android系统7.0及以上机型,快速点击显示toast,发现前面的toast覆盖显示,后面的几个Toast就不再显示。
其处理方法是在每次toast的时候,如果tosat 显示时,就调用cancle方法把之前的close,并设置Toast延时显示。
public class ToastUtils {
private static Toast mToast;
private static Application mContext;
private static Handler mHandler = new Handler(Looper.getMainLooper());
public static void init(Application context){
mContext = context;
}
public static void show(CharSequence sequence){
if (null == mToast){
mToast = Toast.makeText(mContext,sequence,Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER,0,0);
}else{
mToast.cancel();
mToast.setText(sequence);
}
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mToast.show();
}
}, 300);
}
}
使用的时候,只需要在Application的onCreate方法进行初始化。