October 2018
Intermediate to advanced
464 pages
15h 17m
English
This custom Toast changes the default gravity and shape, and adds an image just to show that "it can be done."
The first step is to create a new Toast layout, which we do by inflating our custom_toast layout. Once we have the new layout, we need to get the TextView so we can set our message, which we do with the standard setText() method. With this done, we create a Toast object and set the individual properties. We set the Toast gravity with the setGravity() method. The gravity determines where on the screen our Toast will display. We specify our custom layout with the setView() method call. And just like in the single-line variation, we display the Toast with the show() method.