Android 控制吐司的显示时间

Android 控制吐司的显示时间,android,android-toast,Android,Android Toast,我在我的android应用程序中使用了祝酒。我可以不看面包片,只要我愿意就可以吗 Toast.LENGTH_LONG 及 有人能帮我一些有用的代码段吗。谢谢。试试这个 final Toast toast = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT); toast.show(); new CountDownTimer(10000, 1000)

我在我的android应用程序中使用了祝酒。我可以不看面包片,只要我愿意就可以吗

Toast.LENGTH_LONG

有人能帮我一些有用的代码段吗。谢谢。

试试这个

final Toast toast = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT);
            toast.show();
            new CountDownTimer(10000, 1000)
            {
                public void onTick(long millisUntilFinished) {toast.show();}
                public void onFinish() {toast.cancel();}
            }.start();
享受..

试试这个

final Toast toast = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT);
            toast.show();
            new CountDownTimer(10000, 1000)
            {
                public void onTick(long millisUntilFinished) {toast.show();}
                public void onFinish() {toast.cancel();}
            }.start();

享受..

否无法直接处理此问题,您必须使用handler取消烤面包,如下所示:

 final Toast toast = Toast.makeText(getApplicationContext(), "This message will disappear         in half second", Toast.LENGTH_SHORT);
toast.show();

Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
       @Override
       public void run() {
           toast.cancel(); 
       }
}, 500); // 500ms is the time to cancel the toast.

否无法直接处理此问题,您必须使用handler取消toast,如下所示:

 final Toast toast = Toast.makeText(getApplicationContext(), "This message will disappear         in half second", Toast.LENGTH_SHORT);
toast.show();

Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
       @Override
       public void run() {
           toast.cancel(); 
       }
}, 500); // 500ms is the time to cancel the toast.

你所能做的就是创建一个方法,通过某种循环,让你的吐司尽可能长时间地显示

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();
    }

然后您可以将此方法称为
showtoos(10000)。因此,它将继续循环显示土司,直到持续时间结束,并在持续时间结束时取消土司。

您可以创建一种方法,通过某种循环,使土司显示的持续时间尽可能长

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();
    }

然后您可以将此方法称为
showtoos(10000)。因此,它将继续在循环中显示Toast,直到持续时间结束,并在持续时间结束时取消Toast。

。您确定它将显示10秒吗?我不这么认为:-)是的。它会在10分钟内出现secs@Lalit请尝试编辑答案。。它的工作原理也许你指的是
tag.cancel()
onFinish()
?是的,你的权利。。为错误道歉。。。此外,如果它起作用,你可以接受答案。你确定它会出现10秒钟吗?我不这么认为:-)是的。它会在10分钟内出现secs@Lalit请尝试编辑答案。。它的工作原理也许你指的是
tag.cancel()
onFinish()
?是的,你的权利。。为错误道歉。。。此外,如果它起作用,你可以接受回答者并没有真正回答OP的问题…当这个代码起作用时,它仍然可能对OP没有帮助,因为他想有更长的持续时间。没有真正回答OP的问题…当这个代码起作用时,它仍然可能对OP没有帮助,因为他想有更长的持续时间。