How to short time of Toast notification

Total Post:36

Points:260
 1013  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. 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 Apr-09-2018 01:59:19 AM

Answer

NEWSLETTER

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