Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

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)

customtoast.xml

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,

android:contentDescription='@string/hello_world""

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

android.src-""@drawable/is_launcher""/>

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,

toast.show();

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

FAQs

Recommended Courses

Share With Friend

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

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • 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