ToastUtil工具类
public class ToastUtil {
private static Toast mToast = null;
public static void showToast(Context context, String text, int duration) {
if (mToast == null) {
mToast = Toast.makeText(context, text, duration);
} else {
mToast.setText(text);
mToast.setDuration(duration);
}
mToast.show();
}
}
调用方法:
toastUtil.showToast(MainActivity.this, "tab1", Toast.LENGTH_SHORT);