Customized Toast Messages

Sometimes when you show toast messages in your code you might not want the default length SHORT or LONG to display the toast. Sometimes we need to customize the duration of toast as per our requirements. Today in this example I will show how to customize Toast to display it for longer duration, by using CountDownTimer to call toast.show() repeatedly. I will also explain how to make the toast with counting numbers.

Explore my older post on Customize Toast message with an image.

You should follow the steps I will describe below to make an example of customized toast. I will show 4 methods of toasting so that you can compare and decide which one you need next time when you use toast in your code.

Step1: Create a new android project in your android IDE.

Step2: Write following into your main layout xml:

 

 

Step3: Write following code into your activity:

 

 

Step4: Run to see the output.

toast1

Here Toast 1 and 2 buttons are for the default toast duration LONG and SHORT. Toast 3 will show the toast for 10 secs and Toast 4 button will show 10 secs message with count down timer.

Checkout my previous blog which is a fun screen crack application HERE. Thanks

Leave a Comment: