设置吐司外观长度 [英] Set Toast Appear Length
本文介绍了设置吐司外观长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论如何我可以告诉 Toast 通知只显示指定的时间.通常比普通的 toast 消息要短.
Is there anyway I can tell a Toast Notification to show up only for a specified amount of time. Generally shorter then a regular toast message.
推荐答案
我找到了解决方案,方法是在比标准 Toast 持续时间短的特定延迟后调用 toast.cancel().
I found a solution to this by calling toast.cancel() after a certain delay that is shorter than the standard toast duration.
final Toast toast = Toast.makeText(ctx, "This message will disappear in 1 second", Toast.LENGTH_SHORT);
toast.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
toast.cancel();
}
}, 1000);
这篇关于设置吐司外观长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文