Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.view.Gravity; import android.widget.Toast; public class Main { /** * Posts a new Toast * * @param context * @param text * @param duration */ public static void postToast(Context context, CharSequence text) { postToast(context, text, Toast.LENGTH_SHORT, Gravity.CENTER); } /** * Posts a new Toast * * @param context * @param text * @param duration */ public static void postToast(Context context, CharSequence text, int duration) { postToast(context, text, duration, Gravity.CENTER); } /** * Posts a new Toast * * @param context * @param text * @param duration * @param gravity */ public static void postToast(Context context, CharSequence text, int duration, int gravity) { duration = duration == 0 ? Toast.LENGTH_LONG : duration; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(gravity, 0, 0); toast.show(); } }