Android Custom Toast example

Previous
Next
Android Toast is used to display message for short span of time. Message appears on the screen for short span of time then disappears after some time.

We have already used toast in previous examples like Android SeekBar , Android RatingBar .
In this post, I am going to demonstrate how to make custom toast and use in your app.

Source code:

Lets create Android custom toast example:

Step 1 : Creating Project

Create an android application project named “CustomToastExampleApp”.

Step 2: Put any image in drawable folder with name “custom_toast_image”

Step 3 : Creating custom toast layout file

  • Go to res -> layout
  • Right click on layout
  • Click on New -> File.
  • Create a file named “custom_toast.xml” and paste below code in custom_toast.xml.

Step 4 : Creating Layout

Change res ->layout -> activity_main.xml as below:

Step 5 : Creating MainActivity

Change src/main/packageName/MainActivity.java as below:

It is default MainActivity provided by HelloWorld app.

Step 6 : Running the app

When you run the app, you will get below screen:

When you click on the button, you will get below screen.

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog