HOW TO SHORT TIME OF TOAST NOTIFICATION

Pawan Shukla

Total Post:38

Points:274
Posted by  Pawan Shukla
 800  View(s)
Ratings:
Rate this:
My code is

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

how to show notification for two second

  1. Manoj Pandey

    Post:26

    Points:188
    Re: How to short time of Toast notification

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!