A toast provides a simple popup message that is displayed on the current activity UI screen (e.g. Main Activity).
We can also create toast with single line by passing variables directly to makeText() function. This method takes three parameters context, popup text message, the toast duration. After creating Toast object you can display the toast by using show() method.
Creating a Custom Toast :
If you are not satisfied with simple Toast view in Android, then you can go ahead to make a custom Toast. Actually, custom Toast is a modified simple Toast that makes your UI more attractive. So that when you create a custom Toast then two things are required, one is XML (custom_toast.xml) required for layout view of custom Toast and another is activity class (custom_activity.class) file where you can write Java code. Java class file passes the root View object to the setView(View) method.
This is a XML layout for example purposes, so if you want your own design then you can create your own XML.
- Android | How to Create/Start a New Project in Android Studio?
- Android | AdMob Banner Ads for Android Studio
- Android | AdMob Interstitial Ads for Android Studio
- Guide to Install and Set up Android Studio
- 10 Important Android Studio Shortcuts You Need the Most
- How to create a Stopwatch App using Android Studio
- How to build a simple Calculator app using Android Studio?
- How to scale different Views to all screen sizes in Android Studio?
- Android | How to Request permissions in Android Application?
- Android | How to add Radio Buttons in an Android Application?
- Android | Android Application File Structure
- Android | Running your first Android app
- Android Menus
- Android UI Layouts
- How to use CheckBox in Android
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.