How to display Toast at center of screen

tedris picture tedris · Mar 10, 2013 · Viewed 76.3k times · Source

In Android I want to display a toast message at the bottom of the screen, I tried this:

Toast.makeText(test.this, "bbb", Toast.LENGTH_LONG).show();

It doesn't work, how do I do it correctly?

Answer

Ajay S picture Ajay S · Mar 10, 2013

To display the Toast in center of the screen.

Toast toast = Toast.makeText(test.this, "bbb", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();