Example usage for android.widget Toast setDuration

List of usage examples for android.widget Toast setDuration

Introduction

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

Prototype

public void setDuration(@Duration int duration) 

Source Link

Document

Set how long to show the view for.

Usage

From source file:Main.java

/**
 * Creates a custom {@link Toast} with a custom layout View
 * /*from w w w. ja  va 2  s.  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 void ShowToast(Context context, String strMsg) {
    Toast toast = Toast.makeText(context, strMsg, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(1000);
    toast.show();//from w ww. ja v  a 2s . com
}

From source file:Main.java

public static void showToast(Context context, View view) {
    Toast toast = new Toast(context);
    toast.setView(view);//from ww w  .j a v  a 2  s.c o m
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();
}

From source file:org.wahtod.wififixer.utility.NotifUtil.java

public static void showToast(Context context, String message, int delay) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast, null);
    ImageView image = (ImageView) layout.findViewById(R.id.icon);
    image.setImageResource(R.drawable.icon);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(message);//  w  w  w.  j  av  a 2s .c  o m
    Toast toast = new Toast(context.getApplicationContext());
    toast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 0);
    toast.setDuration(delay);
    toast.setView(layout);
    toast.show();

}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void showNetworkUnavailable(Activity activity) {
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.network_not_available,
            (ViewGroup) activity.findViewById(R.id.nwunavailable));
    Toast toast = new Toast(activity);
    toast.setView(view);//www.  ja v  a2s .co  m
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();

}

From source file:de.baumann.hhsmoodle.helper.helper_main.java

public static void makeToast(Activity activity, String Text) {
    LayoutInflater inflater = activity.getLayoutInflater();

    View toastLayout = inflater.inflate(R.layout.toast,
            (ViewGroup) activity.findViewById(R.id.toast_root_view));

    TextView header = (TextView) toastLayout.findViewById(R.id.toast_message);
    header.setText(Text);/*w  w  w.  j  av a2s .co  m*/

    Toast toast = new Toast(activity.getApplicationContext());
    toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(toastLayout);
    toast.show();
}

From source file:com.andrewshu.android.reddit.common.Common.java

public static void showErrorToast(String error, int duration, Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Toast t = new Toast(context);
    t.setDuration(duration);
    View v = inflater.inflate(R.layout.error_toast, null);
    TextView errorMessage = (TextView) v.findViewById(R.id.errorMessage);
    errorMessage.setText(error);// w w w .j a  v a2 s.  co  m
    t.setView(v);
    t.show();
}

From source file:com.commonsdroid.dialoghelper.DialogHelper.java

/**
 * Show custom toast./*from  ww w. j ava  2s .  c  o  m*/
 *
 * @param context the context
 * @param view the view
 */
public static void showCustomToast(Context context, View view) {
    Toast newCustomToast = new Toast(context);
    newCustomToast.setView(view);
    newCustomToast.setDuration(Toast.LENGTH_LONG);
    newCustomToast.show();
}

From source file:com.commonsdroid.dialoghelper.DialogHelper.java

/**
 * Show custom toast.//from  ww  w  . j av  a 2s .  co  m
 *
 * @param context the context
 * @param view the view
 * @param Duration the duration e.g <code>Toast.LENGTH_SHORT</code> , <code>Toast.LENGTH_LONG</code>
 */
public static void showCustomToast(Context context, View view, int Duration) {
    Toast newCustomToast = new Toast(context);
    newCustomToast.setView(view);
    newCustomToast.setDuration(Duration);
    newCustomToast.show();
}

From source file:com.commonsdroid.dialoghelper.DialogHelper.java

/**
 * Show custom toast.//from  ww  w.j ava 2 s.c o  m
 *
 * @param context the context
 * @param view the view
 * @param gravity the gravity e.g <code>GRAVITY.BOTTOM</code> , <code>GRAVITY.CENTER_VERTICAL</code> , etc
 * @param xoffset the x offset
 * @param yoffset the y offset
 */
public static void showCustomToast(Context context, View view, int gravity, int xoffset, int yoffset) {
    Toast newCustomToast = new Toast(context);
    newCustomToast.setView(view);
    newCustomToast.setDuration(Toast.LENGTH_LONG);
    newCustomToast.setGravity(gravity, xoffset, yoffset);
    newCustomToast.show();
}