/** * * 显示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); } }); }
时间: 2024-10-12 22:39:58