How To Design Custom Toast In Android

Andorid Toast may be used to display data for the brief time period.  A toast includes message to be displayed quickly and fades after a while. The android.widget.Toast course is the subclass of java.lang.Object class.You could even produce custom toast too such as toast displaying picture.  It’s possible to see next page to find the code for custom toast.

Toast course is used to demonstrate telling for a specific period of time.  After sometime it disappears.  It does not obstruct the user interaction.  There are two types of toast messages in android.

  • LENGTH_LONG : With this type toast messages are shown for the longer period of time.
  • LENGTH_SHORT : With this type toast messages are shown for the Shorter period of time.

Now to design custom toast in android we have to add the third party dependency to that we have to add the below line in our gradle.

Now add the maven you can do that by adding the below code in the gradle.

Creating Android User Interface

  • The important thing in android is to design a user interface for the user. So now design our activity_main.xml as below.
toast in android
  • Now Connect the UI component in java file so that user can interact with it. This is How MainActivity.java will look like.

Custom Toast

  • Native Toast

You can add the native toast by adding the below line.

toast in android
  • Success Toast

Without success toast, our application is incomplete to add the success toast in android add the below line.

toast in android
  • Warning Toast

Warning toast are basically used to warn the user. This task is done by adding the below line.

toast in android
  • Error Toast

Where there is success there is an error. So to show this error add the below line.

toast in android
  • Info Toast

This type of toast is basically used to show some info. This is done by adding the below line.

toast in android

That’s it guys our custom toast message is ready. If you have any query then do comment down below. Thank you.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.