the_prole the_prole - 1 month ago 18
Android Question

How to center toast vertically and display at bottom of screen

This is a simple question. I Have this toast that is vertically centered, which appears in the middle of the screen.

Toast toast = Toast.makeText(ctx,"My Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();


How do I center the toast vertically AND display it at the bottom of my screen

Answer

I think you're misunderstanding the meaning of vertical positioning. It means along the y axis – not x. To center it horizontally, and have it at the bottom of the screen – try the following:

toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 0);