Example usage for android.widget Toast getView

List of usage examples for android.widget Toast getView

Introduction

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

Prototype

public View getView() 

Source Link

Document

Return the view.

Usage

From source file:Main.java

public static void showToastView(Context context, String text) {
    Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
    View view = toast.getView();
    view.setBackgroundColor(Color.GREEN);
    toast.setView(view);/* w ww  .  j a  v  a 2 s  . c o  m*/
    toast.show();
}

From source file:Main.java

public static void showShortToastBottom(Context context, int resId) {
    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    TextView v = toast.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);/*from  ww w. ja va 2  s . c om*/
    toast.show();
}

From source file:Main.java

public static void toastGreen(Activity activity, int resId) {
    Toast toast = Toast.makeText(activity, resId, Toast.LENGTH_LONG);
    TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
    v.setBackgroundColor(Color.GREEN);
    toast.show();/*www  .  jav  a2s  . c  o  m*/

}

From source file:Main.java

public static Toast alert(Context ctx, int nResID) {
    Toast t = Toast.makeText(ctx, nResID, Toast.LENGTH_SHORT);
    TextView v = (TextView) t.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);//from  www.j a v a2s .c  om
    t.show();

    return t;
}

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.  java2 s .  c o m*/
    t.show();

    return t;
}

From source file:Main.java

public static void setToastView(Context context, String str) {
    Toast makeText = Toast.makeText(context, "   " + str + "   ", 0);
    TextView textView = (TextView) makeText.getView().findViewById(16908299);
    if (textView != null) {
        textView.setGravity(17);/*w w  w.jav  a 2s  . c  om*/
    }
    makeText.show();
}

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

From source file:Main.java

public static void showCenteredToast(Context context, int resId, int duration) {
    Toast toast = Toast.makeText(context, resId, duration);
    TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
    if (v != null) {
        v.setGravity(Gravity.CENTER);// w  w w  . j a  va  2  s.  c o  m
    }
    toast.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 .j a v a  2 s  . c om*/
    toast.show();
}

From source file:Main.java

/**
 * Show toast message./*from  w  ww . j  a v  a2  s.c om*/
 *
 * @param context Context
 * @param message Text to display
 */
public static void ShowMessage(Context context, String message) {
    if (context != null) {
        if (TOAST != null) {
            TOAST.cancel();
        }
        Toast newToast = Toast.makeText(context, message,
                message.length() < 15 ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
        TextView textView = (TextView) newToast.getView().findViewById(android.R.id.message);
        textView.setGravity(Gravity.CENTER);
        textView.setSingleLine(false);
        newToast.show();
        TOAST = newToast;
    }
}