我怎样才能显示举杯特定时间?时间

2023-09-12 09:18:21 作者:你别皱眉

这是我的样子已经显示吐司 500毫秒。虽然,它显示超过一秒。

This is the way I have to show the Toast for 500 milliseconds. Though, it's showing more than a second.

Toast.makeText(LiveChat.this, "Typing", 500).show(); 

我如何能显示吐司仅为500毫秒?

推荐答案

这不能做。要显示举杯的长度比 Toast.LENGTH_SHORT 短,你必须你想要的时间后取消。是这样的:

This cannot be done. To show a toast for a length shorter than Toast.LENGTH_SHORT, you must cancel it after the time you want. Something like:

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