List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:Main.java
public static void showToast(Context context, String title) { Toast toast = Toast.makeText(context, title, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();//from w ww . j av a2s. c o m }
From source file:Main.java
public static void showToastShort(Context context, String message) { Toast toast = Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();/*from ww w . j a v a2s . c o m*/ }
From source file:Main.java
/** * Posts a new Toast/*from w w w . j a v a2s . c o m*/ * * @param context * @param text * @param duration * @param gravity */ public static void postToast(Context context, CharSequence text, int duration, int gravity) { duration = duration == 0 ? Toast.LENGTH_LONG : duration; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(gravity, 0, 0); toast.show(); }
From source file:Main.java
public static void toastShow(String paramString, Context paramContext) { View localView = LayoutInflater.from(paramContext).inflate(getLayoutId(paramContext, "xdw_toast_item"), null);//w w w.j a v a 2 s .co m Toast localToast = new Toast(paramContext); localToast.setView(localView); localToast.setGravity(17, 0, 0); ((TextView) localView.findViewById(getResId(paramContext, "xdw_toast_mes"))).setText(paramString); localToast.show(); }
From source file:Main.java
public static void toast(Activity activity, String txt) { Toast toast = Toast.makeText(activity, txt, Toast.LENGTH_SHORT); int xoffset = 30, yoffset = 30; toast.setGravity(Gravity.RIGHT, xoffset, yoffset); toast.show();/* ww w. ja va 2 s.com*/ }
From source file:Main.java
/** * Toast dialog with string//from w ww.j av a2s. c o m */ public static void showToast(final String message, final Context context) { final Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.setGravity(Gravity.BOTTOM, 0, 0); toast.show(); }
From source file:Main.java
/** * Toast dialog with string//from w w w . j a v a 2 s. co m */ public static void showToast(final String message, final Activity activity) { final Toast toast = Toast.makeText(activity, message, Toast.LENGTH_LONG); toast.setGravity(Gravity.BOTTOM, 0, 0); toast.show(); }
From source file:Main.java
public static void showToast(final Activity activity, final String message) { activity.runOnUiThread(new Runnable() { @Override// w ww .j a va 2 s .com public void run() { Toast toast = Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0, 80); toast.show(); } }); }
From source file:Main.java
/** * Creates a custom {@link Toast} with a custom layout View * //from w w w. j a v a 2s. c o m * @param context * the context * @param resId * the custom view * @return the created {@link Toast} */ public static Toast makeCustomToast(Context context, int resId) { View view = LayoutInflater.from(context).inflate(resId, null); Toast t = new Toast(context); t.setDuration(Toast.LENGTH_SHORT); t.setView(view); t.setGravity(Gravity.CENTER, 0, 0); return t; }
From source file:Main.java
public static final void showToast(Context context, String tip, boolean isCenter) { int duration = Toast.LENGTH_SHORT; if (TextUtils.isEmpty(tip)) { return;//from ww w . ja v a2 s .com } if (tip.length() >= 15) { duration = Toast.LENGTH_LONG; } Toast toast = Toast.makeText(context, tip, duration); if (isCenter) { toast.setGravity(Gravity.CENTER, 0, 0); } toast.show(); }