Android Custom Toast With Example

Akshay Rana GuJJar
The Startup
Published in
2 min readJul 14, 2020

--

Android Custom Toast

Hello World, today we will be going to see how we can make custom toast and in this tutorial, we will see custom toast with an example. See below as an example.

Android Custom Toast gif

Before starting let’s see.

What is Toast? When to use it?

Toast is a view that contains text which notifies the user with some information.

We can use toast when we want to notify the user.

Making Custom Toast with Example

To make custom toast we need to follow certain steps as follows.

Step 1. Create a Custom Layout for Toast

the first step is to make a layout file for our toast.

To make a layout file, right-click on layout folder under res and select new -> layout resource file.

we will name this file as custom_toast.xml and in this file, we will make our layout which will b shown in the toast. Check the below code for the layout file.

In the above code, we set the id to the parent view and we added an imageview and a textview.

We are keeping things simple so that you can understand better.

our layout looks like this below.

Step 2. Set layout file to the Toast

To trigger the toast we made a button in the activity layout and calling the makeToast function on click.

Let’s see the code in the makeToast function.

Hey if you want to read full article read here: Android Custom Toast With Example

--

--