文章出處
文章列表
在開發的時候我們會遇到點擊顯示第二個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(); } }
文章列表
全站熱搜