1

In android ,by default toast come in bottom of screen.

   Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)",Toast.LENGTH_LONG).show();

How can I place Toast at center of the screen.

volatile
  • 39
  • 5

2 Answers2

3

There are lots of existing questions on this. Use toast.setGravity function for your purpose. See How to change position of Toast in Android? Eg( taken from one of answers on question):

Toast toast= Toast.makeText(getApplicationContext(), 
"Your string here", Toast.LENGTH_LONG);  
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
  • 1
    Props for not only referencing the existing question (and giving it credit) but showing the answer from that link. This is how answers should be given ladies and gentleman. – zgc7009 Sep 18 '14 at 18:41
1

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

for further informations http://developer.android.com/guide/topics/ui/notifiers/toasts.html

Kiloreux
  • 2,220
  • 1
  • 17
  • 24