Toast provides a notification or feedback after a particular operation is complete. For example, after clicking on the scratch card, it might come up as “You Won” or “Better Luck Next time”. It comes up as a popup, and occupies only a certain part of the screen, keeping the primary application visible in the background. We can create custom Toast in Android, which enables us to display a custom message or a text. A good example will be, for an Activity, it can be a text message based on a condition or it can be an image if the condition is false. For creating a custom Toast, a Toast object needs to be created under activity in XML format. A sample code for the same is given below.
With the makeText() method, which uses the following parameters:
Using a makeText() method, we return a well initialized Toast object. The class android.widget.Toast is the subclass of java.lang.Object class.
The two constants of the Toast class are mentioned below.
The popularly used methods of Toast class are.
|