标签:android 项目优化
在我们做登陆验证的时候经常会用到toast来提示用户输入内容的错误等,很多人都是直接用的
Toast.makeText(LoginActivity.this, "请联系小区物管", Toast.LENGTH_SHORT) .show();
public class CustomToast {
private static Toast mToast;
private static Handler mhandler = new Handler();
private static Runnable r = new Runnable() {
public void run() {
mToast.cancel();
};
};
public static void showToast(Context context, String text, int duration) {
mhandler.removeCallbacks(r);
if (null != mToast) {
mToast.setText(text);
} else {
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
}
mhandler.postDelayed(r, 5000);
mToast.show();
}
public static void showToast(Context context, int strId, int duration) {
showToast(context, context.getString(strId), duration);
}
}标签:android 项目优化
原文地址:http://blog.csdn.net/binrong112558058/article/details/44307311