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

后端 未结 4 800
后悔当初
后悔当初 2021-02-11 16:14

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.

Ca

4条回答
  •  耶瑟儿~
    2021-02-11 16:56

    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

提交回复
热议问题