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)