What is the value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT?

28,705

Solution 1

There is another question that answers what you are looking for. The answers are:

private static final int LONG_DELAY = 3500; // 3.5 seconds
private static final int SHORT_DELAY = 2000; // 2 seconds

This was courtesy of FeelGood. You can find the whole thread below.

Can an Android Toast be longer than Toast.LENGTH_LONG?

Hope this helps.

Solution 2

There are only these two constants related to Toast

http://developer.android.com/reference/android/widget/Toast.html#LENGTH_LONG

Why would you want to know their values though? You should always use the constants instead.

Solution 3

They are one and zero as detailed in the Toast documentation. They are the only two values and no others are possible. There is an "indefinite toast hack", but I would not use an application that used it.

Solution 4

LENGTH_SHORT & LENGTH_LONG are mapped to time interval of 1 Second (1000mS) & 5 Seconds (5000mS) respectively,

To see this you need to dig into the AOSP source code of Toast. You can see in the Toast class time interval is decided based on the FLAG

mParams.hideTimeoutMilliseconds = mDuration == Toast.LENGTH_LONG ? LONG_DURATION_TIMEOUT : SHORT_DURATION_TIMEOUT;

where

 static final long SHORT_DURATION_TIMEOUT = 5000;
  static final long LONG_DURATION_TIMEOUT = 1000;

Reference: https://android.googlesource.com/platform/frameworks/base/+/f4bed684c939b0f8809ef404b8609fe4ef849263/core/java/android/widget/Toast.java

Share:
28,705
CoDe
Author by

CoDe

Updated on February 03, 2021

Comments

  • CoDe
    CoDe over 3 years

    I am printing Toast message in my application to show notification but i want to know value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT. What other values i can use.

    Can anyone tell me what is the value of these two variables?