How to set Toast display time less than Toast.LENGTH_SHORT

Zoombie picture Zoombie · May 23, 2011 · Viewed 54.6k times · Source

I want to display toast less than Toast.LENGTH_SHORT, as i feel its taking around 2 seconds. i want to display toast only for half second.

And what is time interval for Toast.LENGTH_SHORT and Toast.LENGTH_LONG ?

Answer

Emran Hamza picture Emran Hamza · Oct 16, 2012

This has worked for me

final Toast toast = Toast.makeText(getApplicationContext(), "The following 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);