List of usage examples for android.widget Toast makeText
public static Toast makeText(Context context, @StringRes int resId, @Duration int duration) throws Resources.NotFoundException
From source file:Main.java
public static void showCenteredToast(Context context, CharSequence text, int duration) { Toast toast = Toast.makeText(context, text, duration); TextView v = (TextView) toast.getView().findViewById(android.R.id.message); if (v != null) { v.setGravity(Gravity.CENTER);//ww w .ja v a2 s. com } toast.show(); }
From source file:Main.java
/** * A method to create a toast message on any screen. * * @param activity : screen on which the toast message should be shown. * @param msg : the message to be shown. *//*from w ww .ja v a 2s . c om*/ public static void createToastMessage(final Activity activity, final String msg) { if (!isNullOrEmpty(msg)) activity.runOnUiThread(new Runnable() { @Override public void run() { Toast toast = Toast.makeText(activity.getApplicationContext(), msg, Toast.LENGTH_SHORT); toast.show(); } }); }
From source file:Main.java
public static void show(Context context, CharSequence message, int duration) { if (isShow)/*from w ww. j a v a 2 s. c om*/ Toast.makeText(context, message, duration).show(); }
From source file:Main.java
public static void showToast(final Context context, final int messageResId) { if (mToast == null) { mToast = Toast.makeText(context, messageResId, Toast.LENGTH_SHORT); } else {//from w w w .j av a2 s . c o m mToast.setText(messageResId); mToast.setDuration(Toast.LENGTH_SHORT); } mToast.show(); }
From source file:Main.java
public static void show(Context context, CharSequence message, int duration) { if (showToast) Toast.makeText(context, message, duration).show(); }
From source file:Main.java
public static void showToast(Context context, CharSequence text) { if (toast == null) { toast = Toast.makeText(context, text, SHORT_DUR); } else {//from w w w .j a v a 2s . com toast.setText(text); toast.setDuration(SHORT_DUR); } toast.show(); }
From source file:Main.java
/** * Shows an error alert dialog with the given message. * /*from w w w . j a v a 2 s . c o m*/ * @param activity * activity * @param message * message to show or {@code null} for none */ public static void showError(final Activity activity, String message) { final String errorMessage = message == null ? "Error" : "[Error ] " + message; activity.runOnUiThread(new Runnable() { public void run() { Toast.makeText(activity, errorMessage, Toast.LENGTH_LONG).show(); } }); }
From source file:Main.java
/** * Show a Toast message//w w w . ja v a 2 s. c om * @param context The context * @param str The string content */ public static void showToast(Context context, String str) { if (context != null) { Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); } }
From source file:Main.java
public static void showLong(Context context, int message) { if (null == toast) { toast = Toast.makeText(context, message, Toast.LENGTH_LONG); // toast.setGravity(Gravity.CENTER, 0, 0); } else {/*from www . ja v a 2 s . c om*/ toast.setText(message); } toast.show(); }