Course Content

Course Content


Custom Notification in Android with Example

Now we will learn how we can create Custom Toast in Android.

Stepwise :

1. So to create a custom Toast, we will first design the layout, for that we have to create two types of layout file -

activity_main.xml (default)


2. When we create any project inside Android, we have two types of content, one is 'Static' and the other is 'Dynamic'.

3. Static content is that which is auto-generated such as the 'activity_main.xml' file of our layout. Dynamic content is the one whose run time changes, meaning that it actually changes when our application is executed.

4. Now we will see how we design 'customtoast.xml'. Here inside the customtoast.xml file, first of all we have to design its layout.

5. So for that we will first use an image view, so for that we have describe the basic properties of image view such as width and height, and along with that we have provided its description as well,


6. After that we have to provide its image resource,


7. After that we will take a text view, which we have given the id and with it, width, height, description, specification have been specified. Meaning that we have created the customtoast.xml file with an image view and text view.

8. Now we will have the java file inside our 'java' folder, open it, and now we have to generate a customtoast, for that we will now use our customtoast.xml file, but to use this thing we have to learn a concept called 'Layout Inflater'.

9. Layout Inflater is a class that is used to create an instance of any xml file of layout. Inshort, it will input the xml file, and build it as a view, meaning that we use Layout Inflater when we want to design a custom view.

LayoutInflater li=getLayoutInflater();

10. After that we will create an instance of view,

Viewlayout=li.inflate(R.layout.customtoast,(ViewGroup)findViewById (R.Id);

11. So this is how we can use Layout inflator and use the layout XML file and can display its view.

12. After that we have to set the properties of Toast here,

Toast toast=newToast(getApplicationContext());

 13. After that we will set all the properties of toast, such as Gravity, Duration, View and show them all in the last,;

14. After this, we will execute our code, as soon as we execute our toast notification will come and our code runs.


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere