Android(安卓)toast弹出时间自定义
16lz
2022-07-25
代码如下:
/** * Toast自定义时间 * Toast对象时间需要为Toast.LENGH_LONG */ public static void showTimeToast(final Toast toast, final int time) { final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { toast.show(); } }, 0, 3000); new Timer().schedule(new TimerTask() { @Override public void run() { toast.cancel(); timer.cancel(); } }, time); }
第一个参数为Toast对象,该对象持续时间参数为Toast.LENGTH_LONG,
第二个参数为Toast显示时间,单位为毫秒。
栗子:
Toast toast = Toast.makeText(TimingDetails.this, "倒计时一秒", Toast.LENGTH_LONG);showTimeToast(toast,1000);
更多相关文章
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- 类和 Json对象
- Python技巧匿名函数、回调函数和高阶函数
- python list.sort()根据多个关键字排序的方法实现
- android中文api(89)——ViewManager
- Android调用天气预报的WebService简单例子
- Android(安卓)Activity的启动
- 修改android系统和watchdog的延时
- Android中文API(144) —— JsonWriter