Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Toast at center of screen

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?

like image 344
tedris Avatar asked Mar 10 '13 10:03

tedris


People also ask

How do you put toast in the middle of the screen?

To display the Toast in center of the screen. If someone wants to adjust the position further, the third argument in setGravity takes in the yAxis offset in pixels. setGravity() should have returned Toast to be able to chain it.

How do you display a toaster?

Display the created Toast Message using the show() method of the Toast class. The code to show the Toast message: Toast. makeText(getApplicationContext(), "This a toast message", Toast.

How do I show a toast at a specific time?

A Toast in Android is a message that appears on the screen for a specific time whenever invoked. This message appears at the bottom of the application leaving some margin at the bottom. In general, a Toast can be displayed for either 2 seconds (Toast. LENGTH_SHORT) or 3.5 seconds (Toast.


1 Answers

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(); 
like image 101
Ajay S Avatar answered Sep 25 '22 17:09

Ajay S