Showing posts with label Toast. Show all posts
Showing posts with label Toast. Show all posts

Wednesday, 19 June 2013

Toast in Android.



We can say Toast is a notification message in a small popup,fills amount of space required for the message and automatically disappear after a timeout.
For instantiating a Toast, we can use makeText() method.it have three paramteres.application Context, the text message, and the duration for the toast.
Code snippets to create a Toast message :
Toast.makeText(getApplicationContext(),"Please enter  username and password",Toast.LENGTH_LONG).show();
we can change the position of toast by using setGravity() method.it have three paramteres like  a Gravity constant, an x-position offset, and a y-position offset.

Toast toast=Toast.makeText(getApplicationContext(), "Please enter  username and password", Toast.LENGTH_LONG);
 toast.setGravity(Gravity.CENTER|Gravity.RIGHT, 0, 0);
 toast.show();


We have two time duration variables in the class Toast.
LENGTH_LONG & LENGTH_SHORT.