Example usage for android.widget Toast setGravity

List of usage examples for android.widget Toast setGravity

Introduction

In this page you can find the example usage for android.widget Toast setGravity.

Prototype

public void setGravity(int gravity, int xOffset, int yOffset) 

Source Link

Document

Set the location at which the notification should appear on the screen.

Usage

From source file:Main.java

public final static void showToastMessage(Context context, String message) {
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.show();/*w  w  w .j a v  a  2s  .c o m*/
}

From source file:Main.java

public static void centerToast(Context context, String message) {
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    toast.show();//from   www .  java2s  .co  m
}

From source file:Main.java

public static void showToast(Context ctx, String message) {
    Toast tost = Toast.makeText(ctx, message, Toast.LENGTH_SHORT);
    tost.setGravity(Gravity.CENTER, 0, 0);
    tost.show();//w w w .  java  2 s .co  m
}

From source file:Main.java

public static void showToast(Context context, String message) {
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.show();//from w  w  w . ja  v  a2 s.com
}

From source file:Main.java

public static void toast(Context mcontext, String toastStr, int i) {
    Toast toast = Toast.makeText(mcontext, toastStr, Toast.LENGTH_SHORT);
    toast.setGravity(i, 0, 0);//Gravity.CENTER
    toast.show();/*www  .  j  a  v a 2 s .c om*/
}

From source file:Main.java

public static void showToast(String message, Context context) {
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();// w w w .  j ava 2s  .c om
}

From source file:Main.java

public static void makeToastMsg(Context context, String message) {
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();//from ww  w.j  a  v  a 2s  . c  om
}

From source file:Main.java

public static void toastInMiddle(Context context, String message) {
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();/*from   w  w  w .  j a v a 2  s .co m*/
}

From source file:Main.java

public static void showLongToastTop(Context context, int resId) {
    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.TOP, 0, 100);
    TextView v = toast.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);// w  w w .j a v  a2 s .co  m
    toast.show();
}

From source file:Main.java

public static void ShowToastCenter(Context context, String strText, int nTime) {
    if (context != null) {
        Toast toast = Toast.makeText(context, strText, nTime);

        toast.setGravity(Gravity.CENTER, 0, 0);

        toast.show();/*from w ww .  jav  a2 s.  c o  m*/
    }

}