When I use Toast
to display some popup text on the screen, it displays the text a little bit above the bottom of the screen, which is the default position.
Now I want to display it in the middle of screen or somewhere according to my choice.
Can anyone guide me how to achieve this?
You can customize the location of your Toast by using:
setGravity(int gravity, int xOffset, int yOffset)
docs
This allows you to be very specific about where you want the location of your Toast to be.
One of the most useful things about the xOffset and yOffset parameters is that you can use them to place the Toast relative to a certain View.
For example, if you want to make a custom Toast that appears on top of a Button, you could create a function like this: