Example usage for android.widget Toast makeText

List of usage examples for android.widget Toast makeText

Introduction

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

Prototype

public static Toast makeText(Context context, @StringRes int resId, @Duration int duration)
        throws Resources.NotFoundException 

Source Link

Document

Make a standard toast that just contains a text view with the text from a resource.

Usage

From source file:Main.java

public static void showTextShort(Context context, String text) {
    if (toast == null) {
        toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
    } else {//from w ww .ja  v  a 2  s  . c  om
        toast.setText(text);
        toast.setDuration(Toast.LENGTH_SHORT);
    }
    toast.show();
}

From source file:Main.java

public static void showTips(Context context, String text) {
    if (mToast == null) {
        mToast = Toast.makeText(context, "", Toast.LENGTH_LONG);
    }/*w  w w  . j a  va 2  s.  c o m*/

    mToast.setText(text);
    mToast.show();
}

From source file:Main.java

public static void showToast(Context context, String msg) {
    if (msg == null || msg.equals("") || msg.length() == 0)
        return;//  w  w  w  . j  a v  a2s . c  o  m
    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}

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);//from   w  w w .ja  v  a 2 s. c  o m
    toast.show();
}

From source file:Main.java

public static void showToast(final Activity context, final String msg) {
    if ("main".equals(Thread.currentThread().getName())) {
        Toast.makeText(context, msg, 1).show();
    } else {//  w  w  w .  j  av a 2  s  .  c o m
        context.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, msg, 1).show();
            }
        });
    }
}

From source file:Main.java

public static void showToast(final Activity context, final String msg) {
    if ("main".equals(Thread.currentThread().getName())) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    } else {/*from   w ww.  j  a  v a2s.c om*/
        context.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

From source file:Main.java

public static void showShort(Context context, CharSequence message) {
    if (isShow)/*from  ww  w. j  a  va 2  s.c  o  m*/
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static Toast alert(Context ctx, String message) {
    Toast t = Toast.makeText(ctx, message, Toast.LENGTH_SHORT);
    TextView v = (TextView) t.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);//from   ww  w  . j  a v  a  2 s  .com
    t.show();

    return t;
}

From source file:Main.java

public static void alert(Context c, String message) {
    Toast.makeText(c, TAG + "-" + message, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static void ShowToast(Activity activity, String str, boolean isLong) {
    if (isLong) {
        Toast.makeText(activity, str, Toast.LENGTH_LONG).show();
    } else {// w w  w.  j a  va2 s.c  o m
        Toast.makeText(activity, str, Toast.LENGTH_SHORT).show();
    }
}