-1

Is there a way to show a Toast message for 30 seconds (without the blinking effect)?

I have already tried the methods on this post, however none of them works for me (Android 9)

Can an Android Toast be longer than Toast.LENGTH_LONG?

On top, I can't use the Snackbar or Statusbar Notification feature for my situation

Ali Sadeghi
  • 397
  • 4
  • 16
Tester2389
  • 149
  • 1
  • 12
  • 2
    did you try this https://blog.cindypotvin.com/toast-specific-duration-android/ ? – Ashish Dec 30 '19 at 12:44
  • Does this answer your question? [Set Android Toast duration to be really long (e.g., 1 minute)](https://stackoverflow.com/questions/21134640/set-android-toast-duration-to-be-really-long-e-g-1-minute) – Ricardo A. Dec 30 '19 at 12:48
  • [Custom toast on Android: a simple example](https://stackoverflow.com/questions/11288475/custom-toast-on-android-a-simple-example/30411107) – Ricardo A. Dec 30 '19 at 12:49
  • Yep, already tried all those methods, as it seems Google has changed some things during the last years – Tester2389 Dec 30 '19 at 13:03

3 Answers3

0

you can use SuperToast for showing toast to user

of other way you can show a dialog box non cancelable and put it in a thread in 30 sec dismiss it but you must handle views and context and this is so hard job

you can try this code maybe work for you :

private Toast mToastToShow;
public void showToast(View view) {
   // Set the toast and duration
   int toastDurationInMilliSeconds = 10000;
   mToastToShow = Toast.makeText(this, "Hello world, I am a toast.", 
                                                Toast.LENGTH_LONG);

   // Set the countdown to display the toast
   CountDownTimer toastCountDown;
   toastCountDown = new CountDownTimer(toastDurationInMilliSeconds, 
                                   1000 /*Tick duration*/) {
      public void onTick(long millisUntilFinished) {
         mToastToShow.show();
      }
      public void onFinish() {
         mToastToShow.cancel();
         }
   };

   // Show the toast and starts the countdown
   mToastToShow.show();
   toastCountDown.start();
}
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
alireza daryani
  • 787
  • 5
  • 16
0

Here you are!

private Toast mToastToShow;
    public void showToast(View view) {
       // Set the toast and duration
       int toastDurationInMilliSeconds = 10000;
       mToastToShow = Toast.makeText(this, "Hello world, I am a toast.",                                                    Toast.LENGTH_LONG);

       // Set the countdown to display the toast
       CountDownTimer toastCountDown;
       toastCountDown = new CountDownTimer(toastDurationInMilliSeconds, 1000 /*Tick duration*/) {
          public void onTick(long millisUntilFinished) {
             mToastToShow.show();
          }
          public void onFinish() {
             mToastToShow.cancel();
             }
       };

       // Show the toast and starts the countdown
       mToastToShow.show();
       toastCountDown.start();
    }
tefek
  • 71
  • 5
0

Short answer:

No

Detailed answer:

You cannot make Toast with custom duration, based on official documentations:

Duration: How long to display the message. Either LENGTH_SHORT or LENGTH_LONG Value is LENGTH_SHORT, or LENGTH_LONG

Any alternative?

In your case you can use alert dialog, popup window or third party libraries such as KoushikToast.

Notice that if you want to use KoushikToast or any other library, you need to add SYSTEM_ALERT_WINDOW permission in your manifest and also grant it manually or programmatically on API 23 and higher.

Ali Sadeghi
  • 397
  • 4
  • 16