通过自定Toast,在显示的时候通过Handler的延时操作,从而控制显示时间,同时,通过动态改变Toast中的文字提示,达到切换Toast的目的:
引用地址:http://blog.sina.com.cn/s/blog_7bac47070101449g.html
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 (mToast != null)
mToast.setText(text);
else
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
mHandler.postDelayed(r, duration);
mToast.show();
}
public static void showToast(Context context, int resId, int duration) {
showToast(context, context.getResources().getString(resId), duration);
}
}