0

I'm new to Android. Now I'm learning about Toast. Is it possible to position a toast?

Whenever I toast, it is coming in bottom of the screen.

Here is my code:

Context context = getApplicationContext();
Toast toast = Toast.makeText(context, "Saved successfully.", Toast.LENGTH_SHORT);
toast.show();

3 Answers3

1

You can use setGravity(int, int, int) method.

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);

Toast Documentation: http://developer.android.com/guide/topics/ui/notifiers/toasts.html

Gravity Documentation: http://developer.android.com/reference/android/view/Gravity.html

Gokul Nath KP
  • 15,485
  • 24
  • 88
  • 126
1

Hi try this example to position and customize toast in android

NARESH REDDY
  • 682
  • 4
  • 11
1

Try this,

Toast toast = Toast.makeText(context, "Saved successfully.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM, 0, 200);
toast.show();
Poovizhirajan N
  • 1,263
  • 1
  • 13
  • 29
DropAndTrap
  • 1,538
  • 16
  • 24