What is the value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT?
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开发者_C百科 anyone tell me what is the value of these two variables?
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.
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.
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.
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
精彩评论