A toast in a tiny popup offers easy feedback about an project. It only fills out the amount of space needed for the message and remains accessible and interacting with the current operation. After a timeout, toasts quickly fade away.
Toasts are not interactable. If the user is expected to respond to a status update, consider a Notification instead.
First, instantiate a Toast object with one of the makeText() methods. This method takes up parameters: the Context code, the text message and the toast length. It returns a pre initialized Toast object. You can display the toast notification with show(), as shown in the following example:
|
|
You can also chain your methods and avoid sticking to the Toast object as follows:
|
|
A regular toast notification, oriented horizontally, appears near the bottom of the page.location can be modified with the method setGravity(int, int, int). That accepts three parameter constants of gravity, an offset of x-position and an offset of y-position.
If you agree, for example, that the toast will appear in the top-left corner, you can segravity to this:
|
|