Android--Toast时间

/**
	 * 
	 * 显示toast,自己定义显示长短。
	 * param1:activity  传入context
	 * param2:word   我们需要显示的toast的内容
	 * param3:time length  long类型,我们传入的时间长度(如500)
	 */
	public static void showToast(final Activity activity, final String word, final long time){
		activity.runOnUiThread(new Runnable() {	
			public void run() {
				final Toast toast = Toast.makeText(activity, word, Toast.LENGTH_LONG);
				toast.show();
				Handler handler = new Handler();
			        handler.postDelayed(new Runnable() {
			           public void run() {
			               toast.cancel(); 
			           }
			    }, time);
			}
		});
	}
posted @ 2016-05-26 01:04  舞阳  阅读(1956)  评论(0编辑  收藏  举报