How to show custom toast in android with example

How to show custom toast in android with example

In this tutorial i am going to explain about how to show custom toast in android with example. In my previous tutorial i have explained about

Implementation :

Now we will see the implementation of . Before we proceed with the example let us check what is meant by toast. As per this link

A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. Toasts automatically disappear after a timeout.




Now to explain about how to show custom toast in android with example let us create a new project in android studio and name it as AndroidToastExample.  Now open the project and add customtoast.xml file inside res drawable folder. Add the below code inside customtoast.xml.

Now open the activity_main.xml file and add the below code.

The above code contains two buttons. One to show normal toast and another one to show custom toast. Now open the MainActivity.java file and update below code.

In the above code i have two onclick listeners defined. One for normal toast button another one is for showing custom toast. My string resource file will look like below.

Below is the AndroidManifest.xml file.

Output:

Now if you run the program you can see the output of how to show custom toast in android with example.

Output of how to show custom toast in android with example

Source Code:

You can download the source code of how to show custom toast in android with example from the below link.

Source code of how to show custom toast in android with example.

 

 

 

Conclusion:

Hope you learned how to show custom toast in android with example. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Tags:

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!