Android开发之Toast的快去替换
在开发的时候我们会遇到点击显示第二个Toast的时候,当前Toast还没有显示完,导致第二个Toast不能立马显示,下面来解决这个问题:
用下面的工具类就行了:
import android.content.Context; import android.widget.Toast; public class MyUtil { private static Toast mToast; public static void showToast(Context context, int resId, int duration){ showToast(context, context.getString(resId), duration); } public static void showToast(Context context, String msg, int duration) { if (mToast == null) { mToast = Toast.makeText(context, msg, duration); } else { mToast.setText(msg); } mToast.show(); } }