How to increase the duration of toast message in android
I saw many questions regarding the increase in Toast duration. Many developer struggle with this even I also face this when I was new in android developing.So, Here are the two easy and fast techniques to increase the Toast duration.
1) Using For Loop :
int duration = 7;
for (int i = 0; i < duration; i++)
{
Toast.makeText(Activity.this, "Hello", Toast.LENGTH_LONG).show();
}
2) Using CountDown Timer :
/* Duration is in seconds.
If you wish to write something like this (7 * 1000).
*/
int duration = 7000;
/* Duration is in seconds.
You can change the interval time according to your need.
Here we take interval of every one second.
*/
int interval = 1000;
CountDownTimer countDownTimer = new CountDownTimer(duration, interval)
{
@Override
public void onTick(long l)
{
Toast.makeText(Activity.this, "Hello", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
}
}.start();
From the above both 1 and 2 code Toast shows up-to 7 to 8 second long.You can change the duration according to your use.
1) Using For Loop :
int duration = 7;
for (int i = 0; i < duration; i++)
{
Toast.makeText(Activity.this, "Hello", Toast.LENGTH_LONG).show();
}
2) Using CountDown Timer :
/* Duration is in seconds.
If you wish to write something like this (7 * 1000).
*/
int duration = 7000;
/* Duration is in seconds.
You can change the interval time according to your need.
Here we take interval of every one second.
*/
int interval = 1000;
CountDownTimer countDownTimer = new CountDownTimer(duration, interval)
{
@Override
public void onTick(long l)
{
Toast.makeText(Activity.this, "Hello", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
}
}.start();
From the above both 1 and 2 code Toast shows up-to 7 to 8 second long.You can change the duration according to your use.
Comments
Post a Comment