
Step 3: Write following into your MainActivity. It contains a message to be displayed quickly and disappears after specified period. Step 2: Write following into your activity_main.xml: In Android, Toast is used to display information for a period of time. Step 1: Create a new android application in your IDE. tGravity(Gravity.TOP | Gravity.LEFT, 50, 100) Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT)

This method accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.įor example the following code will show the Toast at top-left corner with X-Offset and Y-Offset as 50 and 100 respectively. The code which we are going to develop will show how to create toast messages in different positions by altering Gravity. You will learn how to alter the standard position of toast with the help of setGravity(int, int, int) method. You should read my previous posts on toast messages if not yet read the list below: By default it is displayed at the bottom of the Application, but sometimes we don’t want it to be at the bottom. A toast is the simple popup message which provides simple feedback about an operation. Public void setMargin (float horizontalMargin, float verticalMargin)Ĭhanges the horizontal and vertical margin difference.Today in this tutorial, we will discuss about how to position the toast message in Android applications.Īlthough I assume you must know what is Toast in android, but for beginners, I will define it in brief. Makes the toast containing text and duration. Public static Toast makeText(Context context, CharSequence text, int duration)

The widely used methods of Toast class are given below. Constantĭisplays view for the long duration of time.ĭisplays view for the short duration of time. There are only 2 constants of Toast class which are given below. Toast class is used to show notification for a particular interval of time. You can visit next page to see the code for custom toast. You can also create custom toast as well for example toast displaying image. A toast contains message to be displayed quickly and disappears after sometime.

Andorid Toast can be used to display information for the short period of time.
