Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Toast display time less than Toast.LENGTH_SHORT

Tags:

android

toast

I want to display toast less than Toast.LENGTH_SHORT, as i feel its taking around 2 seconds. i want to display toast only for half second.

And what is time interval for Toast.LENGTH_SHORT and Toast.LENGTH_LONG ?

like image 404
Zoombie Avatar asked May 23 '11 08:05

Zoombie


People also ask

How many seconds does Toast Length_short displays a Toast message?

A Toast in Android is a message that appears on the screen for a specific time whenever invoked. This message appears at the bottom of the application leaving some margin at the bottom. In general, a Toast can be displayed for either 2 seconds (Toast. LENGTH_SHORT) or 3.5 seconds (Toast.

How do you change the duration of a Toast?

There is no way to directly change the duration for which the toast is shown using the show() method without reimplementing the whole Toast class in your application, but there is a workaround. You can use a android. os. CountDownTimer to count down the time for which to display a toast.

Can an android Toast be longer than Toast Length_long?

27 Answers. Show activity on this post. If you dig deeper in android code, you can find the lines that clearly indicate, that we cannot change the duration of Toast message.

Can we set a custom layout for a Toast?

If a simple text message isn't enough, you can create a customized layout for your toast notification. To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView (View) method.


1 Answers

This has worked for me

final Toast toast = Toast.makeText(getApplicationContext(), "The following message will disappear in half second", Toast.LENGTH_SHORT);     toast.show();      Handler handler = new Handler();         handler.postDelayed(new Runnable() {            @Override            public void run() {                toast.cancel();             }     }, 500); 
like image 58
Emran Hamza Avatar answered Oct 20 '22 00:10

Emran Hamza