Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Showing Toast for a specific duration

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 348
    Comment on it

    Basically we have two options for selecting the duration of the Toast.

    First is SHORT duration, which is 2 seconds and another is LONG duration that is 3.5 seconds.

    We cannot change the duration of the Toast directly. To change the time of the Toast, I am using CountDownTimer class and set the toast time duration. Below is the code

    private Toast myToast;
        public void showToast() {
    
            int toastDuration = 20000;
            myToast = Toast.makeText(this, "Toast Duration!!!!!", Toast.LENGTH_LONG);
    
    
            CountDownTimer countDownTimer;
            countDownTimer = new CountDownTimer(toastDuration, 1000 ) {
                public void onTick(long millisUntilFinished) {
                    myToast.show();
                }
                public void onFinish() {
                    myToast.cancel();
                }
            };
    
    
            myToast.show();
            countDownTimer.start();
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: