4

I try to set my Toast show duration like 1minute. I try this:

  final Toast toast = Toast.makeText(getApplicationContext(), "MESSAGE", Toast.LENGTH_LONG );
  toast.show();

    Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
               @Override
               public void run() {
                   toast.cancel(); 
                   }
            }, 60000);

Thanks for your help.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
Merv
  • 55
  • 1
  • 2
  • 8

6 Answers6

8

Since LENGTH_SHORT is 2 seconds (and LENGTH_LONG is 3.5 seconds), try this:

for (int i=0; i < 30; i++)
{
    Toast.makeText(this, "MESSAGE", Toast.LENGTH_SHORT).show();
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
4

There are only two possible Toast durations: short (2 sec) and long (3.5 sec).

If you need a more persistent message, use a dialog or include the message in your layout.

One easy way to make context-sensitive messages in your layout with custom durations is the Crouton library.

laalto
  • 150,114
  • 66
  • 286
  • 303
3

Take a look at this answer.

The values of LENGTH_SHORT and LENGTH_LONG are 0 and 1. This means they are treated as flags rather than actual durations so I don't think it will be possible to set the duration to anything other than these values.

Community
  • 1
  • 1
Mario Stoilov
  • 3,411
  • 5
  • 31
  • 51
1
final Toast tag = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT);

tag.show();

new CountDownTimer(9000, 1000) {

    public void onTick(long millisUntilFinished) {tag.show();}
    public void onFinish() {tag.show();}

}.start();

See Similar Question and answer there.

Community
  • 1
  • 1
msj121
  • 2,812
  • 3
  • 28
  • 55
0

Toasts are not meant to be used like that. Toasts are transient and Android has defined them to be either SHORT or LONG.

If you want, you can create a Dialog than completely emulated the appearance of a Toast, but I would use a dismissable dialog or a notification as it could be frustrating for the user to have a Toast showing for a whole minute without the possibility to dismiss it.

s1m3n
  • 623
  • 6
  • 21
0

if you want to show toast by your choice you have to make a custom toast with time duartion that you want

                View toastview = findViewById(R.id.customtoastlayout);
                LinearLayout mToastLayout = 
                toastview.findViewById(R.id.toastlayout);
                TextView text = toastview.findViewById(R.id.customToastText);
                text.setText(message);
                Toast toast = new Toast(getApplicationContext());
                toast.setGravity(Gravity.TOP | Gravity.RIGHT, 90, 0);
                toast.setDuration(duration);//custom duartion
                toast.setView(mToastLayout);
                toast.show();
Nadeem Bhat
  • 1,032
  • 7
  • 10