EXAMPLE 1
Below is how you can show a basic Toast.
Toast toast = Toast.makeText(getApplicationContext(), "This is a Message to user", Toast.LENGTH_LONG); // initiate the Toast with context, message and duration toast.show(); // display the Toast
The 3rd Parameter is for duration in abouve example. You can use Toast.LENGTH_LONG or Toast.LENGTH_SHORT for long or short duration.
EXAMPLE 2
You can also use setGravity() to set Position for the Toast.
Toast toast = Toast.makeText(getApplicationContext(), "Simple Toast In Android", Toast.LENGTH_LONG); // initiate the Toast with context, message and duration toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);// You can set gravity for the Toast. toast.show(); // display the Toast
You can use Libraries such as
FancyToast
to show some classic Toasts in Android.
0 Please Share a Your Opinion.:
Comment something useful and creative :)