Home > DeveloperSection > Forums > How to short time of Toast notification
Pawan Shukla

Total Post:35

Points:253
Posted on    March-05-2015 5:43 AM

 Android Android 
Ratings:


 1 Reply(s)
 479  View(s)
Rate this:
My code is

Toast.makeText(getApplicationContext(), "My message", Toast.LENGTH_SHORT).show();

how to show notification for two second



Manoj Pandey

Total Post:26

Points:188
Posted on    March-05-2015 5:53 AM

Use following code instead of your code 

final Toast toast = Toast.makeText(getApplicationContext(), "My message",

Toast.LENGTH_SHORT);

toast.show();

toast.setGravity(Gravity.CENTER, 0, 0);

new CountDownTimer(2000, 2000) {

@Override

public void onTick(long millisUntilFinished) {

toast.show();

}

@Override

public void onFinish() {

toast.cancel();

}

}.start();


Modified On Mar-05-2015 05:54:10 AM

Don't want to miss updates? Please click the below button!

Follow MindStick