Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to specify the position of a Toast? [duplicate]

Tags:

android

toast

Possible Duplicate:
how to change position of Toast in android?

I have to show a Toast, when the user presses a Button, but I want to show it a little more down on the screen.

How can I do this?

This is the code of my Toast:

Toast.makeText(getApplicationContext(),
getString(R.string.emailregisternotentered),
Toast.LENGTH_SHORT).show();

Solved:

Toast toast= Toast.makeText(getApplicationContext(), 
getString(R.string.emailregisternotentered), Toast.LENGTH_SHORT);  
//Toast.makeText(getApplicationContext(), getString(R.string.emailregisternotentered),
//Toast.LENGTH_SHORT).show();
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
like image 690
NullPointerException Avatar asked Dec 18 '10 12:12

NullPointerException


People also ask

How do you change the position of a toast message?

Positioning your Toast A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.

How do you avoid a toast if there's one toast already being shown?

You can prevent identical same Toast displaying in a screen by event function. You can terminate the Toast displaying process by setting cancel event property in beforeOpen Event.

What is toast explain it with example?

A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. Toasts automatically disappear after a timeout.

How do I show a toast at a specific time in Android?

In general, a Toast can be displayed for either 2 seconds (Toast. LENGTH_SHORT) or 3.5 seconds (Toast. LENGTH_LONG). In this article, we will show you how you could display Toast for longer or shorter in Android.


2 Answers

Here is the documentation:

http://developer.android.com/guide/topics/ui/notifiers/toasts.html#Positioning

like image 64
Daniel A. White Avatar answered Oct 06 '22 23:10

Daniel A. White


Toast.setGravity is one option.

like image 33
cx0der Avatar answered Oct 07 '22 00:10

cx0der