码迷,mamicode.com
首页 > 移动开发 > 详细

Android--Toast时间

时间:2016-05-26 06:17:30      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

/**
	 * 
	 * 显示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);
			}
		});
	}

Android--Toast时间

标签:

原文地址:http://www.cnblogs.com/wuyong0818/p/5529478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!