Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the duration of a Toast LENGTH_LONG and LENGTH_SHORT

I need the exact duration of LENGTH_LONG and LENGTH_SHORT in milliseconds (ms). Also I need to know if the duration of Toast message with LENGTH_LONG will have the same duration in any phone and with any API version.

Does someone know where is the duration defined ?, I mean defined in ms . I know that LENGTH_LONG is some int const with value 1. But I could not find where is the actual duration defined.

like image 658
Lukap Avatar asked Nov 01 '11 10:11

Lukap


People also ask

How long is toast Length_short?

A Toast in Android is a message that appears on the screen for a specific time whenever invoked. This message appears at the bottom of the application leaving some margin at the bottom. In general, a Toast can be displayed for either 2 seconds (Toast. LENGTH_SHORT) or 3.5 seconds (Toast.

What does toast Length_short mean?

Show the view or text notification for a long period of time. int. LENGTH_SHORT. Show the view or text notification for a short period of time.

How can I increase my toast time?

There is no way to directly change the duration for which the toast is shown using the show() method without reimplementing the whole Toast class in your application, but there is a workaround. You can use a android. os. CountDownTimer to count down the time for which to display a toast.

What are the 2 constants of toast class when are they used?

The Toast class contains two predefined constants you can use: Toast. LENGTH_SHORT and Toast.


2 Answers

Answered here. Like you mentioned Toast.LENGTH_SHORT and Toast.LENGTH_LONG are not in ms but 0 or 1.

The actual durations are:

private static final int LONG_DELAY = 3500; // 3.5 seconds private static final int SHORT_DELAY = 2000; // 2 seconds 
like image 103
Lars Avatar answered Oct 12 '22 12:10

Lars


The Toast.LENGTH_SHORT and Toast.LENGTH_LONG are just flags.
You can find here the official android source where these flags are defined:

public class NotificationManagerService extends SystemService {      static final int LONG_DELAY = PhoneWindowManager.TOAST_WINDOW_TIMEOUT;     /** Amount of time (in milliseconds) a toast window can be shown. */     //public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds     static final int SHORT_DELAY = 2000; // 2 seconds      private void scheduleDurationReachedLocked(ToastRecord r)     {        mHandler.removeCallbacksAndMessages(r);        Message m = Message.obtain(mHandler, MESSAGE_DURATION_REACHED, r);        int delay = r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY;        //....        mHandler.sendMessageDelayed(m, delay);      } } 
like image 35
Gabriele Mariotti Avatar answered Oct 12 '22 13:10

Gabriele Mariotti