Friday, February 28, 2014

Customize Toast Example Code

public class ToastUtil {
  /**
   * @param context
   * @param text text to be shown on toast
   * @param val toast duration
   * @param color background color for toast
   * @param size toast text size
   * @param textColor toast text color
   * @return
   */
  public static Toast makeText(Context context, CharSequence text, int val, int color, float size,
      int textColor) {
    Toast toast = new Toast(context);
    TextView tv = new TextView(context);
    tv.setText(text);
    tv.setBackgroundColor(color);
    tv.setTextSize(size);
    tv.setTextColor(textColor);
    toast.setView(tv);

    toast.setDuration(val);
    toast.show();
    // return toast;
    return toast;
  }
}

USE Below Code to show Toast:
 ToastUtil.makeText(this, "welcome", Toast.LENGTH_SHORT, Color.GREEN, 30, Color.RED).show();

No comments:

Post a Comment