0

Possible Duplicate:
Set Toast Appear Length

In Android,there are only two elements to control toast's time: Toast.LENGTH_SHORT and Toast.LENGTH_LONG.But I want to let the Toast display only 0.5 seconds or less.How can I do?Who can help me? Very thanks!

Community
  • 1
  • 1
XX_brother
  • 1,657
  • 4
  • 18
  • 15
  • Toast doesn't support this. Check the following answer for the details: http://stackoverflow.com/a/6095362/648313. You may however try the following hack: http://stackoverflow.com/a/9715422/648313 – Volo Apr 20 '12 at 12:58
  • I have developed a custom Toast class with which you can show Toast for a specified amount of time... have a look at my answer http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long/21203554#21203554 – Gopal Gopi Jan 18 '14 at 12:45

2 Answers2

8

The values of LENGTH_SHORT and LENGTH_LONG are 0 and 1. This means they are treated as flags rather than actual durations so I don't think it will be possible to set the duration to anything other than these values.

If you want to display a message to the user for longer, consider a Status Bar Notification. Status Bar Notifications can be programmatically cancelled when they are no longer relevant.

But this is not end you can do like this

for (int i=0; i < 2; i++)
{
    Toast.makeText(this, "blah", Toast.LENGTH_LONG).show();
}

to double the time. If you specify 3 instead the 2 it will triple the time..etc.

Chirag Patel
  • 11,416
  • 3
  • 26
  • 38
-1

Replace Toast.LENGTH_LONG or Toast.LENGTH_SHORT with 500

kmb64
  • 1,513
  • 2
  • 17
  • 29