controling敬酒的显示时间 [英] controling the displaying time of a toast

查看:263
本文介绍了controling敬酒的显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的祝酒词在我的机器人应用程序。我可以显示在面包只要我愿意,而不是

I used toasts in my android application. Can I show the toast as long as i wish instead of

Toast.LENGTH_LONG

Toast.LENGTH_SHORT

有人可以帮助我做一些有益的code段。谢谢你。

can someone help me with some helpful code segment. Thank you.

推荐答案

你可以做的就是创建一个方法,它具有某种只要周围循环,使您的吐司显示为持续时间你想要它,

What you can do is create a method which with some kind of looping around to make your Toast display as long as duration you want it,

private void showToast(int duration) {
    final Toast toast = Toast.makeText(getBaseContext(), 
                                                      "This is a Toast Message!",
                Toast.LENGTH_SHORT);
    toast.show();
    new CountDownTimer(duration, 500) {
            public void onTick(long millisUntilFinished) {
                toast.show();
            }
            public void onFinish() {
                toast.cancel();
            }

        }.start();
    }

然后你就可以调用此方法为 showToast(10000); 。那么,究竟它会做的是它会保持显示土司循环,直到持续时间和持续时间完成将取消敬酒。

And then you can call this method as showToast(10000);. So, what it will do is it will keep showing the Toast in loop until the duration and will cancel the toast as the duration is completed.

这篇关于controling敬酒的显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆